ajax를 사용하려면 jquery를 불러오는건 필수다.

 

그렇지 않게 하려면 순수 자바스크립트로 짜야하는데 그 방법은

XMLHttpRequest을 사용하면 된다.

 

기본 사용 법은 간단하다.


var xhr = new XMLHttpRequest();

xhr.open('post', 'url');
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {

            console.log(xhr.responseText);
        } else alert("요청오류 : " + xhr.status);
    }
}
xhr.send(form);

'WEB > 비동기 통신' 카테고리의 다른 글

[Ajax] 기본  (0) 2017.11.28



function ajax_example(idx){
    $.ajax({ 
        url: url, 
        type: "post",  // 전송할 타입
        //datatype : "JSON", // success에서 받을 타입
        data: { 
            "idx" : idx 
        }, //전송할 파라미터
        success : function(data){ 
            alert(data); 
        } 
    });
}

+ Recent posts