back

  • person_pin
  • calendar_today
  • remove_red_eye

[jquery / ajax] ajax 간단하게 호출하는 방법

페이지 정보

작성자 webpaper 댓글 0건 조회 13,085회 작성일 19-02-20 09:36

본문

ajax 를 사용해서, 간단하게 컨텐츠를 호출하는 방법 
 

<!-- 호출받을 html -->
<div class="ajax_inform">
     
</div>
 
<!-- 호출할 html call.html -->
<div class="ajax_content">
     
</div>


ajax_inform으로 call.html의 컨텐츠를 호출합니다. 



function callContent(){
 
    var url = "call.html";
     
    $.ajax({
        type:"POST",
        url:url,
        dataType : "html",
        success: function(html){
            $(".ajax_inform").html(html);
             
        },
        error: function(xhr, status, error) {
            alert(error);
        }  
    });
}


callContent() 를 실행하면, 아래와 같이 됩니다. 

<!-- 실행 후 호출받은 html -->
<div class="ajax_inform">
    <div class="ajax_content">
 
    </div>
</div>


간단하게 페이지 이동없이 리스트를 갱신하거나 

컨텐츠를 호출해올 수 있습니다.