{"id":2777,"date":"2014-03-11T00:17:42","date_gmt":"2014-03-10T16:17:42","guid":{"rendered":"https:\/\/sdeno.com\/?p=2777"},"modified":"2015-12-10T14:37:46","modified_gmt":"2015-12-10T06:37:46","slug":"ajax%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=2777","title":{"rendered":"ajax\u7b14\u8bb0"},"content":{"rendered":"<p>*\u6ce8\u610fajax\u5fc5\u987b\u662f\u5728\u642d\u5efa\u597d\u7684web\u670d\u52a1\u5668\u4e0b\u8bbe\u7f6e<\/p>\n<pre>$.ajax({\r\n  type:\"\",\r\n  url:'',\r\n  timeout:\r\n  async:\r\n  cache:\r\n  data:\r\n  dataType:\r\n  beforeSend:\r\n  complete:\r\n  success:\r\n  error:\r\n  jsonp:\r\n  contentType:\r\n  dataFilter:\r\n  global:\r\n  ifModified:\r\n  username:\r\n  password:\r\n  processData:\r\n  scriptCharset:\r\n});\r\n\r\n\u66f4\u591a\u53c2\u6570\u8bf7\u53c2\u8003\uff1a<a href=\"https:\/\/sdeno.com\/jq\/jQuery.ajax.html\" target=\"_blank\">https:\/\/sdeno.com\/jq\/jQuery.ajax.html<\/a><\/pre>\n<p>&nbsp;<\/p>\n<p>ajax\u662f\u591a\u6280\u672f\u96c6\u5408\uff0c\u53ea\u8981\u6d4f\u89c8\u5668\u652f\u6301js\u5c31\u80fd\u8fd0\u884cajax<br \/>\n\u51cf\u8f7b\u670d\u52a1\u5668\u548c\u5e26\u5bbd\u8d1f\u62c5\u3002<br \/>\nload()\u662f\u5c40\u90e8\u65b9\u6cd5 \u6bd4\u8f83\u9002\u5408\u505a\u4e00\u4e9b\u9759\u6001\u9875\u9762\u5904\u7406<\/p>\n<p>\u4e3e\u4f8b<br \/>\nindex.htm<br \/>\n&lt;button&gt;&lt;\/button&gt;<br \/>\n&lt;div id=&#8221;box&#8221;&gt;&lt;\/div&gt;<\/p>\n<p>index.htm\u6587\u4ef6\u91cc\u9762\u7684#box\u91cc\u9762\u8981\u52a0\u8f7d\u4e00\u4e9b\u5185\u5bb9\u8fdb\u53bb<br \/>\n\u53ef\u4ee5\u8fd9\u4e48\u5199<br \/>\n$(&#8216;#button&#8217;).click(function(){<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html&#8217;);<br \/>\n});<\/p>\n<p>#box\u91cc\u9762\u52a0\u8f7d\u8fdb\u6765\u4e86test.html\u91cc\u9762\u7684\u5185\u5bb9<\/p>\n<p>load()\u63d0\u4ea4\u65b9\u5f0f\u9ed8\u8ba4\u662fget \u4e8e\u662f\u5730\u5740\u5c31\u53ef\u4ee5\u8fd9\u4e48\u63d0\u4ea4<br \/>\n\u4ee5get\u5e26\u53c2\u6570\u63d0\u4ea4\u7ed9\u670d\u52a1\u5668<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html?a=b&amp;c=d&#8217;);<br \/>\nget\u53ef\u4ee5\u5e26\u53c2\u6570\u63d0\u4ea4\u6570\u636e\u7ed9\u670d\u52a1\u5668<br \/>\n\u5185\u5bb9\u8fc7\u6ee4<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html .url&#8217;);<br \/>\n\u83b7\u53d6\u5f97\u5230\u7684test.html\u5185\u5bb9\u8fdb\u884c\u7b5b\u9009 \u4e0a\u9762\u610f\u601d\u662f\u628a<br \/>\n\u540d\u4e3aclass=&#8221;url&#8221;\u7684\u5143\u7d20\u5185\u5bb9\u52a0\u8f7d\u8fdb\u5230#box\u91cc\u9762\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5Post\u65b9\u5f0f\u63d0\u4ea4\u53c2\u6570\u7ed9\u670d\u52a1\u5668<br \/>\n$(&#8216;#button&#8217;).click(function(){<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html&#8217;,{<br \/>\nurl:&#8217;ycku&#8217;<br \/>\n});<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u56de\u8c03\u51fd\u6570<\/p>\n<p>response \u53c2\u6570\u5c31\u662f\u83b7\u53d6\u5f97\u5230\u7684test.html\u5185\u5bb9<br \/>\n\u4f5c\u7528\u5c31\u662f\u628a\u5f97\u5230\u7684\u5185\u5bb9\u9700\u8981\u8fdb\u884c\u7f16\u8f91\u65f6\u7528\u5230\u3002<br \/>\n$(&#8216;#button&#8217;).click(function(){<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html&#8217;,{<br \/>\nurl:&#8217;ycku&#8217;<br \/>\n},function(response,status,xhr){<br \/>\n$(&#8216;#box&#8217;).html(response+&#8217;123&#8242;);<br \/>\n});<br \/>\n});<br \/>\nstatus\u662f\u6307\u5982\u679c\u83b7\u53d6\u5230\u7684\u5185\u5bb9\u72b6\u6001\uff0c\u6210\u529f\u65f6\u600e\u4e48\u6837<br \/>\n\u5931\u8d25\u65f6\u600e\u4e48\u6837\u3002success error<\/p>\n<p>$(&#8216;#button&#8217;).click(function(){<br \/>\n$(&#8216;#box&#8217;).load(&#8216;test.html&#8217;,{<br \/>\nurl:&#8217;ycku&#8217;<br \/>\n},function(response,status,xhr){<br \/>\nif(status==&#8217;success&#8217;){<br \/>\n\u5982\u679c\u83b7\u53d6\u5230\u5185\u5bb9\u6210\u529f\u540e\u8981\u505a\u4ec0\u4e48\u4ee3\u7801\u5199\u8fd9\u91cc..<br \/>\n}<br \/>\n});<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>xhr\u662f\u4e00\u4e2a\u603b\u5bf9\u8c61\u5b83\u91cc\u9762\u7684\u5c5e\u6027\u5c31\u6709response\u548cstatus\uff0c<br \/>\n\u56e0\u4e3aresponse\u548cstatus\u5f88\u91cd\u8981\u6240\u4ee5\u5f00\u53d1\u7684\u65f6\u5019\u5c31\u72ec\u7acb\u5199\u4e86\u51fa\u6765\u3002<br \/>\nxhr\u5bf9\u8c61\u67094\u4e2a\u5c5e\u6027\u5206\u522b\u662f\uff1a<br \/>\nresponseText xhr.responseText \u8ddf response\u529f\u80fd\u4e00\u6837<br \/>\nresponseXML xhr.responseXML<br \/>\nstatus xhr.status \u83b7\u53d6\u5185\u5bb9\u6210\u529f\u8fd4\u56de200<br \/>\n$.get()<br \/>\n$(&#8216;input&#8217;).click(function(){<br \/>\n$.get(&#8216;test.php?url=ycku&#8217;,function(response,status,xhr){<br \/>\n$(&#8216;#box&#8217;).html(response);<br \/>\n});<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>$(&#8216;input&#8217;).click(function(){<br \/>\n$.get(&#8216;test.php&#8217;,&#8217;url=ycku&#8217;,function(response,status,xhr){<br \/>\n$(&#8216;#box&#8217;).html(response);<br \/>\n});<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>$(&#8216;input&#8217;).click(function(){<br \/>\n$.get(&#8216;test.php&#8217;,{<br \/>\nurl:&#8217;ycku&#8217;<br \/>\n},function(response,status,xhr){<br \/>\n$(&#8216;#box&#8217;).html(response);<br \/>\n});<br \/>\n});<br \/>\n$.post()\u8ddf$.get()\u5dee\u4e0d\u591a\uff0c\u53ea\u662f\u4e0d\u80fd\u7528\u5e26?\u8bf7\u6c42\u670d\u52a1\u5668\u4f20\u9012\u5185\u5bb9<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>$.getJSON\u7528\u6cd5\u4e5f\u662f\u8ddfget\u548cpost\u5dee\u4e0d\u591a<\/p>\n<p>$(&#8216;input&#8217;).click(function(){<br \/>\n$.getJSON(&#8216;test.php&#8217;,{<br \/>\nurl:&#8217;ycku&#8217;<br \/>\n},function(response,status,xhr){<br \/>\nalert(response[0].url); \u00a0\/\/\u6570\u7ec4\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u5e76\u4e14\u662f\u5bf9\u8c61\u5c5e\u6027url<br \/>\n});<br \/>\n});<\/p>\n<p>JSON\u5185\u5bb9\u662f\uff1a<\/p>\n<p>[{url:&#8217;\u4f60\u597d&#8217;}]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>$.getScript()<\/p>\n<p>\u4e00\u822c\u6211\u4eec\u5728\u8c03\u7528JS \u7684\u65f6\u5019\u90fd\u8981\u52a0\u8f7d\u5230\u9875\u9762\u4e2d\u4e0d\u7ba1\u7528\u4e0d\u7528\u90fd\u5df2\u7ecf\u52a0\u8f7d\u8c03\u7528\u4e86\uff0c\u4f46\u662f\u6211\u4eec\u8981\u4e4b\u540e\u88ab\u8c03\u7528\u7684\u65f6\u5019\u624d\u52a0\u8f7d\u8fdb\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528$.getScript()\u3002<\/p>\n<p>$(&#8216;input&#8217;).click(function(){<\/p>\n<p>$.getScript(&#8216;test.js&#8217;);<br \/>\n});<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>$.ajax\u53ef\u4ee5\u53d6\u4ee3\u4e0a\u9762\u6240\u6709\u7684\u65b9\u6cd5<\/p>\n<p><a href=\"https:\/\/sdeno.com\/?p=3206\" target=\"_blank\">$.ajax()\u65b9\u6cd5\u53c2\u6570\u8be6\u89e3<\/a><\/p>\n<p>$.ajax\u5178\u578b\u7684\u7528\u6cd5<br \/>\n$(&#8216;input&#8217;).click(function(){<br \/>\n$.ajax({<br \/>\ntype:&#8217;POST&#8217;,<br \/>\nurl:&#8217;test.php&#8217;,<br \/>\ndata:{url:&#8217;ycku&#8217;},<br \/>\nsuccess:function(response,status.xhr){ $(&#8216;#box&#8217;).html(response) }<br \/>\n});<br \/>\n});<br \/>\n\u5229\u7528$.ajax\u628a\u8868\u5355\u7684\u6570\u636e\u4f20\u7ed9\u670d\u52a1\u5668<br \/>\n$(&#8216;form input[type=button]&#8217;).click(function(){ \/\/\u70b9\u51fb\u6309\u94ae\u63d0\u4ea4\u65f6<br \/>\n$.ajax({<br \/>\ntype:&#8217;POST&#8217;, \/\/\u5c06\u6570\u636e\u4ee5Post\u65b9\u5f0f\u4f20\u7ed9\u670d\u52a1\u5668<br \/>\nurl:&#8217;test.php&#8217;, \/\/\u5c06\u6570\u636e\u4f20\u7ed9test.php\u6587\u4ef6<br \/>\ndata:{<br \/>\nuser:$(&#8216;form input[name=user]&#8217;).val(), \/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;user&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\nemail: $(&#8216;form input[name=email]&#8217;).val(),\/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;email&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\n},<br \/>\nsuccess:function(response,status.xhr){ $(&#8216;#box&#8217;).html(response) } ,\/\/\u5728\u4ecetest.php\u8bf7\u6c42\u6570\u636e<br \/>\ntimeout:3000, \/\/\u5982\u679cajax\u52a0\u8f7d\u65f6\u95f4\u8d85\u8fc73\u5206\u949f\uff0c\u5c31\u505c\u6b62\u8fd0\u884c\u4e86\u3002<br \/>\nglobal:false \/\/ajax\u9ed8\u8ba4\u662f\u5168\u5c40\uff0c\u52a0\u4e0a\u8fd9\u7684ajax\u5c31\u4e0d\u63a5\u53d7\u5176\u4ed6\u7684\u5168\u5c40\u4e8b\u4ef6\u4e86<br \/>\n});<br \/>\n});<br \/>\n\u5bf9\u4e8e\u8868\u5355\u591a\u7684\u53ef\u4ee5\u4f7f\u7528.serialize()<br \/>\ndata:$(&#8216;form&#8217;).serialize()<\/p>\n<p>serialize()\u83b7\u53d6\u5230\u7684\u6570\u636e\u5c31\u662fURL\u7f16\u7801\u5b57\u7b26,\u4f8b\u5982@ %23<\/p>\n<p>serializeArray()\u83b7\u53d6\u5230\u7684\u6570\u636e\u662f\u4ee5\u5bf9\u8c61\u5f62\u5f0f\u5c01\u88c5\u7684\u3002<br \/>\n\u83b7\u53d6\u65b9\u6cd5\uff1a<br \/>\n$(&#8216;form input[name=sex]&#8217;).click(function(){<br \/>\nvar json = $(this)serializeArray();<br \/>\n$(&#8216;#box&#8217;).html(json[0].name);<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>$.ajaxSetup({ \/\/$.ajaxSetup()\u53ef\u4ee5\u5c06\u591a\u4f59\u7684\u90e8\u5206\u5c01\u88c5<br \/>\ntype;&#8217;POST&#8217;;<br \/>\nurl:&#8217;test.php&#8217;,<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>\u5982\u679c\u63d0\u4ea4\u7684\u6570\u636e\u662f\u4ee5\u5bf9\u8c61\u7684\u5f62\u5f0f\u63d0\u4ea4\u7684\uff0c\u4f8b\u5982\uff1a<br \/>\ndata:{<br \/>\nuser:$(&#8216;form input[name=user]&#8217;).val(), \/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;user&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\nemail: $(&#8216;form input[name=email]&#8217;).val(),\/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;email&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\n},<br \/>\n\u4e0a\u9762\u662f\u4ee5\u5bf9\u8c61\u7684\u5f62\u5f0f\u4f20\u4e2a\u670d\u52a1\u5668\u3002<\/p>\n<p>\u9700\u8981\u63d0\u4ea4\u7684\u5bf9\u8c61\u6570\u636e\u89e3\u6790\uff0c\u9700\u8981\u7528\u5230$.param<br \/>\ndata:$.param({<br \/>\nuser:$(&#8216;form input[name=user]&#8217;).val(), \/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;user&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\nemail: $(&#8216;form input[name=email]&#8217;).val(),\/\/\u4f20\u9012\u7684\u6570\u636e\u5c31\u662fname=&#8217;email&#8217;\u91cc\u9762\u7684\u6570\u636e<br \/>\n}),<br \/>\n\u4e0a\u9762\u662f\u628a\u5bf9\u8c61\u8f6c\u6210URL\u5730\u5740\u7684\u5f62\u5f0f\u7a7f\u7ed9\u670d\u52a1\u5668<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u7528ajax\u7684\u65f6\u5019\u9047\u5230\u7f51\u901f\u5f88\u6162\u7684\u65f6\u5019,\u8981\u7ed9\u4e00\u4e2a\u6e29\u99a8<br \/>\n\u63d0\u793a,\u4f8b\u5982&#8221;\u6b63\u5728\u52a0\u8f7d\u4e2d&#8221;\u7684\u6548\u679c<\/p>\n<p>\u4f4e\u4e8e1.8\u7684\u7248\u672c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u65b9\u6cd5\uff1a<br \/>\n$(&#8216;.loading&#8217;).ajaxStart(function(){<br \/>\n$(this).show();<br \/>\n}).ajaxStop(function(){<br \/>\n$(this).hide();<br \/>\n});<br \/>\n1.8\u4ee5\u540e\u7684\u7248\u672c\u4f7f\u7528\u8fd9\u6837<br \/>\n$(document).ajaxStart(function(){<br \/>\n$(&#8216;.loading&#8217;).show(); \/\/ajax\u8fd8\u6ca1\u52a0\u8f7d\u5b8c\u5c31\u6267\u884c\u8fd9\u91cc<br \/>\n}).ajaxStop(function(){<br \/>\n$(&#8216;.loading&#8217;).hide(); \/\/ajax\u52a0\u8f7d\u5b8c\u5c31\u6267\u884c\u8fd9\u91cc<br \/>\n});<br \/>\najaxStart\u548cajaxStop\u662f\u5168\u5c40\u4e8b\u4ef6\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u9519\u8bef\u63d0\u793a<\/p>\n<p>\u9002\u7528\u4e8e$.ajax\u7684\u9519\u8bef\u63d0\u793a<br \/>\n$.ajax({<br \/>\ntype:&#8217;POST&#8217;, \/\/ajax\u9009\u62e9POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<br \/>\nurl:&#8217;use.php&#8217;, \/\/\u5c06\u6570\u636e\u63d0\u4ea4\u5230\u8fd9\u4e2a\u6587\u4ef6<br \/>\ndata:$(&#8216;form&#8217;).serialize(), \/\/\u83b7\u53d6\u5230form\u4e2d\u6240\u6709\u63d0\u4ea4\u7684\u6570\u636e<br \/>\nsuccess:function(response,status,xhr){ \/\/\u63d0\u4ea4\u7ed9use.php\u7684\u6570\u636e\u6210\u529f\u540e\u5c31\u6267\u884c\u7684\u51fd\u6570<br \/>\n$(&#8216;#box&#8217;).html(response); \/\/\u83b7\u53d6\u63d0\u4ea4\u7ed9use.php\u6210\u529f\u7684\u6570\u636e<br \/>\n},<br \/>\ntimeout:3000, \/\/\u5982\u679c3\u5206\u949f\u8fd8\u6ca1\u80fd\u663e\u793a\u5185\u5bb9\u5c31\u5fc5\u987b\u505c\u6b62\u8fd0\u884cajax<br \/>\nglobal:false, \/\/\u5c06\u6b64ajax\u8bbe\u7f6e\u4e3a\u5c40\u90e8,\u5c31\u4e0d\u80fd\u63a5\u53d7\u5176\u4ed6\u5168\u5c40\u529f\u80fd\u4e86<br \/>\nerror:function(xhr,errorText,errorType){<br \/>\nalert(&#8216;\u9519\u8bef&#8217;); \/\/ \u627e\u4e0d\u5230url\u5c31\u63d0\u793a\u9519\u8bef<br \/>\nalert(errorText+&#8217;:&#8217;+errorType);<br \/>\nalert(xhr.status+&#8217;:&#8217;+xhr.statusText);<br \/>\n}<br \/>\n});<br \/>\n\u9002\u7528\u4e8e$.post\u7684\u9519\u8bef\u63d0\u793a<br \/>\n$.post(&#8216;use.php&#8217;).error(function(xhr,errorText,errorType){<br \/>\nalert(&#8216;\u9519\u8bef&#8217;); \/\/ \u627e\u4e0d\u5230url\u5c31\u63d0\u793a\u9519\u8bef<br \/>\nalert(errorText+&#8217;:&#8217;+errorType);<br \/>\nalert(xhr.status+&#8217;:&#8217;+xhr.statusText);<br \/>\n});<br \/>\nerror() $.post\u5c40\u90e8\u7684\u65b9\u6cd5<br \/>\n\u4f7f\u7528\u5168\u5c40\u9519\u8bef\u63d0\u793aajaxError(),\u53ea\u8981\u662f\u5168\u5c40\u7684$.ajax $.get $.post\u51fa\u73b0\u4e86\u9519\u8bef<br \/>\n\u90fd\u4f1a\u7edf\u4e00\u8c03\u7528\u4ee5\u4e0b\u9519\u8bef\u63d0\u793a\uff0c\u5982\u679c\u662f\u52a0\u4e0a\u4e86global:false\u5c31\u4e0d\u4f1a\u8c03\u7528\u5176\u4ed6\u5168\u5c40\u4e8b\u4ef6<\/p>\n<p>$(document).ajaxError(function(event,xhr,settings,infoError){<br \/>\nalert(xhr.status+&#8217;:&#8217;+xhr.statusText);<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u662fajax\u6267\u884c\u5931\u8d25\u540e\u6267\u884c\u7684\u65b9\u6cd5\uff0c\u4e0b\u9762\u4ecb\u7ecdajax\u6267\u884c\u6210\u529f\u540e\u6267\u884c\u7684\u65b9\u6cd5\u3002<br \/>\n\u5168\u5c40\u4e8b\u4ef6ajaxSend(),ajaxComplete(),ajaxSuccess(),ajaxError()<\/p>\n<p>$(document).ajaxSend(function(){<br \/>\nalert(&#8216;\u6b63\u8981\u4f46\u662f\u8fd8\u6ca1\u89e6\u53d1ajax\u4e4b\u524d\uff0c\u6267\u884c\u8fd9\u91cc&#8217;);<br \/>\n}).ajaxComplete(function(){<br \/>\nalert(&#8216;\u4e0d\u7ba1ajax\u6267\u884c\u6210\u529f\u8fd8\u662f\u5931\u8d25ajax\u8fd0\u884c\u7ed3\u675f\u65f6\uff0c\u6700\u540e\u90fd\u6267\u884c\u8fd9\u91cc&#8217;);<br \/>\n}).ajaxSuccess(function(){<br \/>\nalert(&#8216;ajax\u6267\u884c\u6210\u529f\u624d\u6267\u884c\u8fd9\u91cc&#8217;);<br \/>\n}).ajaxError(function(){<br \/>\nalert(ajax\u6267\u884c\u5931\u8d25\u624d\u6267\u884c\u8fd9\u91cc&#8221;);<br \/>\n});<br \/>\n\u8bf7\u6c42\u6210\u529f\u540e\u7684\u5c40\u90e8\u4e8b\u4ef6\u5199\u6cd5<br \/>\n$.post\u6ca1\u6709\u5c40\u90e8\u7684\u6267\u884cajax\u524d\u7684\u89e6\u53d1\u4e8b\u4ef6<\/p>\n<p>$(&#8216;form input[type=button]&#8217;).click(function(){<br \/>\n$.post(&#8216;use.php&#8217;,$(&#8216;form&#8217;).serialize()).success(function(){<\/p>\n<p>}).complete(function(){<\/p>\n<p>}).error(function(){<\/p>\n<p>});<br \/>\n});<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>$.ajax({<br \/>\ntype:&#8217;POST&#8217;, \/\/ajax\u9009\u62e9POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<br \/>\nurl:&#8217;use.php&#8217;, \/\/\u5c06\u6570\u636e\u63d0\u4ea4\u5230\u8fd9\u4e2a\u6587\u4ef6<br \/>\ndata:$(&#8216;form&#8217;).serialize(), \/\/\u83b7\u53d6\u5230form\u4e2d\u6240\u6709\u63d0\u4ea4\u7684\u6570\u636e<br \/>\nsuccess:function(response,status,xhr){ \/\/\u63d0\u4ea4\u7ed9use.php\u7684\u6570\u636e\u6210\u529f\u540e\u5c31\u6267\u884c\u7684\u51fd\u6570<br \/>\n$(&#8216;#box&#8217;).html(response); \/\/\u83b7\u53d6\u63d0\u4ea4\u7ed9use.php\u6210\u529f\u7684\u6570\u636e<br \/>\n},<br \/>\ntimeout:3000, \/\/\u5982\u679c3\u5206\u949f\u8fd8\u6ca1\u80fd\u663e\u793a\u5185\u5bb9\u5c31\u5fc5\u987b\u505c\u6b62\u8fd0\u884cajax<br \/>\nglobal:false, \/\/\u5c06\u6b64ajax\u8bbe\u7f6e\u4e3a\u5c40\u90e8,\u5c31\u4e0d\u80fd\u63a5\u53d7\u5176\u4ed6\u5168\u5c40\u529f\u80fd\u4e86<br \/>\nerror:function(xhr,errorText,errorType){<br \/>\nalert(&#8216;\u9519\u8bef&#8217;); \/\/ \u627e\u4e0d\u5230url\u5c31\u63d0\u793a\u9519\u8bef<br \/>\nalert(errorText+&#8217;:&#8217;+errorType);<br \/>\nalert(xhr.status+&#8217;:&#8217;+xhr.statusText);<br \/>\n},<br \/>\ncomplete:function(){<\/p>\n<p>},<br \/>\nbeforeSend:function(){<\/p>\n<p>},<br \/>\nerror:function(){<\/p>\n<p>}<br \/>\n});<\/p>\n<p><a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/03\/ajax_j1.txt\">ajax_j1<\/a><br \/>\n<a href=\"http:\/\/www.w3cschool.cn\/ajax_ajax.html\" target=\"_blank\">http:\/\/www.w3cschool.cn\/ajax_ajax.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>*\u6ce8\u610fajax\u5fc5\u987b\u662f\u5728\u642d\u5efa\u597d\u7684web\u670d\u52a1\u5668\u4e0b\u8bbe\u7f6e $.ajax({ type:&#8221;&#8221;, url:&#8221;, time [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-2777","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/2777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2777"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/2777\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}