jQuery.ajax({

type : "GET" //"POST", "GET" // 1.9.0 이상부턴 method 사용 ("POST", "GET", "PUT", "DELETE")

//,target : "#div_id" // 결과값 해당 div에 찍음 ( 테스트안해봄 )

, async : true // 비동기:true, 동기:false ( jsonp타입 등 일부 지원 안함 )

, url : "http://test.com/test" //Request URL

, dataType : "html" //전송받을 데이터의 타입 

//"xml", "html", "script", "json" 등 지정 가능 

//미지정시 자동 판단

, timeout : 30000 //제한시간 지정

, cache : false  //true, false

, data : "" //$("#inputForm").serialize() //서버에 보낼 파라메터

//form에 serialize() 실행시 a=b&c=d 형태로 생성되며 한글은 UTF-8 방식으로 인코딩

//"a=b&c=d" 문자열로 직접 입력 가능

//{a:b, c:d} json 형식 입력 가능

, contentType: "application/x-www-form-urlencoded; charset=UTF-8"

, error : function(request, status, error) {

//통신 에러 발생시 처리

}

, success : function(response, status, request) {

//통신 성공시 처리

}

, beforeSend: function() {

//통신을 시작할때 처리

}

, complete: function() {

//통신이 완료된 후 처리

}


});



// async를 지원하지않을 땐  마지막에 .done 함수를 붙여서 사용하는 방법도..

jQuery.ajax({

type : "GET"  //"POST", "GET" // 1.9.0 이상부턴 method 사용 ("POST", "GET", "PUT", "DELETE")

, url : "http://test.com/test" //Request URL

, dataType : "jsonp"

.

.

.

, success : function(response, status, request) {

//통신 성공시 처리

jQuery('#multi').append(response);    

}


}).done(function(res) { 

return 2;

}); 

'프로그래밍 > javascript' 카테고리의 다른 글

callback 간단예제  (0) 2018.03.06
클로저 간단예제  (0) 2018.03.06
js 캡쳐  (0) 2018.03.05
highcharts 예제  (0) 2018.03.05
jQuery 정리  (0) 2018.02.28

+ Recent posts