新版jquery的ajax调用 , jquery1.5以上
原文出处:http://api.jquery.com/jQuery.ajax/,该链接页面底部有代码展示
示例1:
$.ajax({ method: "POST", url: "some.php", data: { name: "John", location: "Boston" } }) .done(function( msg ) { alert( "Data Saved: " + msg ); });
示例2:
var xmlDocument = [create xml document]; var xmlRequest = $.ajax({ url: "page.php", processData: false, data: xmlDocument }); xmlRequest.done( handleResponse );
示例3:
var menuId = $( "ul.nav" ).first().attr( "id" ); var request = $.ajax({ url: "script.php", method: "POST", data: { id : menuId }, dataType: "html" }); request.done(function( msg ) { $( "#log" ).html( msg ); }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); });