반응형


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." );
                           });

 

 

 

 

반응형

+ Recent posts