CI 묻고 답하기

제목 jQuery, ajax, json 데이터 html에 표현하기
글쓴이 작성시각 2014/10/30 04:09:26
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 20209   RSS
안녕하세요! 프로그램을 배운지 얼마 안되는 왕초보입니다. 건 한달째 이것 저것 봐도 뭐가뭔지 잘 모르겠네요.. 고수분들 알려주세요... T.T.....
div의 name을 눌렀을때 namenaver란 글자가 id가 hithit인 div에 찍혀서 화면에 나오게 하고 싶은데 아무리해도 안되네요... firebug에 보면 뭔가 되는것 같기는 한데.. 어떻게하면 html화면에 나오게 할 수 있는지 알려주세요....T.T


controller 부분
echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />';
echo json_encode(array('result'=>true, 'hit'=>$this->input->post('hit')."naver")); 

view 부분
<div style="color:#000;" id="hit">name</div>
<div style="color:#000;" id="hithit"></div>

view의 script 부분
$('#hit').click( function() {  
    $.ajax({ 
        url:'http://localhost/index.php/dd/hit_badge_f',
        dataType:'json',
        type:'POST',
        data:{'hit':$('#hit').html()},        
        success:function(result){
                        if(result["result"]==true){
                          $("#hithit").html(result["hit"]);
            }           
        }
    });
})

view의 div의 name 클릭시
firefox의 firebug결과 헤더부분
Connection Keep-Alive
Content-Encoding gzip
Content-Length 108
Content-Type text/html
Date Wed, 29 Oct 2014 19:05:01 GMT
Keep-Alive timeout=5, max=100
Server Apache
Vary Accept-Encoding
X-Frame-Options SAMEORIGIN
X-Powered-By PHP/5.4.33

firefox의 firebug결과 응답부분
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />{"result":true,"hit":"namenaver"}


 
 다음글 다른 도메인간 CI 세션공유 (1)
 이전글 각 model 클래스간에 공유하는 방법을 알고 싶습니다... (1)

댓글

한대승(불의회상) / 2014/10/30 07:31:50 / 추천 0
컨트롤러 부분
// echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />';
echo json_encode(array('result'=>true, 'hit'=>$this->input->post('hit')."naver")); 
view의 스크립트 부분
$('#hit').click( function() {  
    $.ajax({ 
        url:'http://localhost/index.php/dd/hit_badge_f',
        dataType:'json',
        type:'POST',
        data:{'hit':$('#hit').html()},        
        success:function(result){
                        if(result["result"]==true){
                          $("#hithit").html(result.hit); // json
            }           
        }
    });
})
/ 2014/10/30 11:00:58 / 추천 0
한대승(불의회상)님 정말 감사합니다. 
바로 되네요.... 복받으세요!! ^^