ajax() 메소드는 비동기 요청을 수행.
http://api.jquery.com/jQuery.ajax/
http://www.w3schools.com/jquery/ajax_ajax.asp
jQuery.ajax( url [, settings ] )Returns: jqXHR
$.ajax({
url:"demo_test.txt",
success:function(result){
$("#div1").html(result);
}});
getJSON() 메소드는 AJAX HTTP Get 요청을 사용하여 JSON 데이터를 가져온다.
http://api.jquery.com/jQuery.getJSON/
http://www.w3schools.com/jquery/ajax_getjson.asp
jQuery.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] )Returns: jqXHR
$.getJSON('http://yoururl?callback=?', function(data){alert(data)});
var jqxhr = $.getJSON( "example.json", function() {console.log( "success" );})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() { console.log( "complete" );
});
// perform other work here ...
// Set another completion function for the request abovejqxhr.complete(function() { console.log( "second complete" ); });
jqxhr.complete(function() { console.log( "second complete" ); });
getScript() 메소드는 AJAX HTTP GET 요청을 이용하여 javascript를 실행한다.
http://api.jquery.com/jQuery.getScript/
jQuery.getScript( url [, success(script, textStatus, jqXHR) ] )Returns: jqXHR
$.getScript("demo_ajax_script.js");
$.getScript("ajax/test.js", function(data, textStatus, jqxhr) {
console.log(data); //data returned
console.log(textStatus); //success
console.log(jqxhr.status); //200
console.log('Load was performed.');});
$.getScript("ajax/test.js").done(function(script, textStatus) {
console.log( textStatus );})
.fail(function(jqxhr, settings, exception) {
$( "div.log" ).text( "Triggered ajaxError handler." );
});
'프로그래밍 > Script' 카테고리의 다른 글
Sencha Touch vs jQuery Mobile (0) | 2013.07.30 |
---|---|
자바스크립트 레퍼런스 모음 (0) | 2013.07.29 |
[jQuery] 10 Best jQuery Plugins to Create Dynamic Layouts, like pintrest (0) | 2013.07.26 |
[HTML5] 12 Popular Responsive HTML5 Frameworks (0) | 2013.07.26 |
[jQuery] 30 Awesome jQuery Plugins All Designers Should Check Today (0) | 2013.07.26 |