jQuery学习笔记——AJAX

jQuery——AJAX

(1) .load()方法:$(selector).load(URL,data,callback);

如: $("#div1").load("sample.txt",function(responseTxt,statusTxt,xhr){

  if(statusTxt=="success"){

    alert("外部内容加载成功!");

  }else if(statusTxt=="error"){

    alert("Error:"+xhr.status+": "+xhr.statusText+"");

  }

});

 

(2) .get()方法: $.get(URL,callback);

$("#btn1").click(function(){

  $.get("demo_test.asp",function(data,status){

    alert("Data: "+data+"\nStatus: "+status+"");

  });

});

 

(3) .post()方法: $.post(URL,data,callback);

$.post("demo_test_post.asp",{

  name:"Norton",

  city:"ShenZhen"

},function(data,status){

  alert("Data: "+data+"\nStatus: "+status+"");

});

 

转载于:https://www.cnblogs.com/Min-min/p/6054254.html

你可能感兴趣的:(jQuery学习笔记——AJAX)