1. $.ajax 同步和异步请求
1 $.ajax({ 2 type: "POST", 3 url: "some.php", 4 async : true, // true 异步,false 同步 5 // or data:{name:"John",locationi:"Boston"} 6 data: "name=John&location=Boston", 7 success: function(msg){ 8 alert( "Data Saved: " + msg ); 9 } 10 });
2. $.get 请求
jQuery.get(url, [data], [callback], [type]) String,Map,Function,String,请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax
1 $.get("test.cgi", { name: "John", time: "2pm" },function(data){ 2 alert("Data Loaded: " + data); 3 });
jQuery.getJSON(url, [data], [callback])
3.$.post 请求
jQuery.post(url, [data], [callback], [type]) String,Map,Function,String
1 $.post("test.php", { name: "John", time: "2pm" }, function(data){ 2 process(data); 3 });
时间: 2024-11-09 18:57:42