{"id":101550,"date":"2026-09-07T00:36:31","date_gmt":"2026-09-06T16:36:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/101550.html"},"modified":"2026-09-07T00:36:31","modified_gmt":"2026-09-06T16:36:31","slug":"js-ajax%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%ef%bc%88%e4%b8%80%ef%bc%89%ef%bc%9a%e4%bb%8e%e5%8e%9f%e7%94%9fxhr%e5%88%b0axios%ef%bc%8c%e5%86%8d%e5%88%b0json-server%e6%a8%a1%e6%8b%9f%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/101550.html","title":{"rendered":"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e"},"content":{"rendered":"<h3>\u524d\u8a00<\/h3>\n<p>AJAX\u662f\u73b0\u4ee3\u524d\u7aef\u5f00\u53d1\u4e2d\u4e0e\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u4eceAJAX\u57fa\u7840\u6982\u5ff5\u8bb2\u8d77&#xff0c;\u7cfb\u7edf\u8bb2\u89e3HTTP\u534f\u8bae\u3001\u539f\u751fXMLHttpRequest\u53d1\u9001GET\u8bf7\u6c42\u3001axios\u5e93\u7684\u4f7f\u7528\u3001GET\u8bf7\u6c42\u53c2\u6570\u4f20\u9012\u3001\u6570\u636e\u6e32\u67d3\u5b9e\u6218\u4ee5\u53caJSON Server\u642d\u5efa\u6a21\u62df\u63a5\u53e3\u3002\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9&#xff0c;\u4f60\u5c06\u5177\u5907\u5b8c\u6574\u7684\u524d\u540e\u7aef\u6570\u636e\u4ea4\u4e92\u80fd\u529b\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u539f\u751fAJAX\u4ecb\u7ecd<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662fAJAX<\/h4>\n<p>AJAX\u5168\u79f0\u4e3a Asynchronous JavaScript And XML&#xff08;\u5f02\u6b65\u7684JS\u548cXML&#xff09;\u3002\u901a\u8fc7AJAX\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u5411\u670d\u52a1\u5668\u53d1\u9001\u5f02\u6b65\u8bf7\u6c42&#xff0c;\u6700\u5927\u7684\u4f18\u52bf\u662f&#xff1a;\u65e0\u5237\u65b0\u83b7\u53d6\u6570\u636e&#xff0c;\u6309\u9700\u8bf7\u6c42&#xff0c;\u63d0\u9ad8\u7f51\u7ad9\u6027\u80fd\u3002<\/p>\n<table>\n<tr>\n<p>\u7279\u6027<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u672c\u8d28\u200b<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u662f\u65b0\u7684\u7f16\u7a0b\u8bed\u8a00&#xff0c;\u800c\u662f\u5c06\u73b0\u6709\u6807\u51c6\u7ec4\u5408\u4f7f\u7528\u7684\u65b0\u65b9\u5f0f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6838\u5fc3\u80fd\u529b\u200b<\/p>\n<\/td>\n<td>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u5411\u670d\u52a1\u5668\u53d1\u9001\u5f02\u6b65\u8bf7\u6c42<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6700\u5927\u4f18\u52bf\u200b<\/p>\n<\/td>\n<td>\n<p>\u65e0\u9700\u5237\u65b0\u9875\u9762\u5373\u53ef\u4e0e\u670d\u52a1\u5668\u901a\u4fe1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6027\u80fd\u63d0\u5347\u200b<\/p>\n<\/td>\n<td>\n<p>\u6309\u9700\u8bf7\u6c42\u6570\u636e&#xff0c;\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8d44\u6e90\u52a0\u8f7d<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.2 AJAX\u7684\u7279\u70b9<\/h4>\n<h5>\u4f18\u70b9<\/h5>\n<table>\n<tr>\n<p>\u4f18\u70b9<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u65e0\u5237\u65b0\u901a\u4fe1\u200b<\/p>\n<\/td>\n<td>\n<p>\u65e0\u9700\u5237\u65b0\u9875\u9762\u5373\u53ef\u4e0e\u670d\u52a1\u5668\u7aef\u901a\u4fe1&#xff0c;\u901f\u5ea6\u5feb<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6309\u9700\u66f4\u65b0\u200b<\/p>\n<\/td>\n<td>\n<p>\u5141\u8bb8\u6839\u636e\u7528\u6237\u4e8b\u4ef6&#xff08;\u9f20\u6807\u79fb\u5165\u3001\u70b9\u51fb\u7b49&#xff09;\u66f4\u65b0\u90e8\u5206\u9875\u9762\u5185\u5bb9<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u7f3a\u70b9<\/h5>\n<table>\n<tr>\n<p>\u7f3a\u70b9<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u6ca1\u6709\u6d4f\u89c8\u5386\u53f2\u200b<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u80fd\u56de\u9000\u5230\u4e4b\u524d\u7684AJAX\u8bf7\u6c42\u72b6\u6001<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5b58\u5728\u8de8\u57df\u95ee\u9898\u200b<\/p>\n<\/td>\n<td>\n<p>\u53d7\u540c\u6e90\u7b56\u7565\u9650\u5236<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>SEO\u4e0d\u53cb\u597d\u200b<\/p>\n<\/td>\n<td>\n<p>\u641c\u7d22\u5f15\u64ce\u722c\u866b\u96be\u4ee5\u6293\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u5185\u5bb9<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e8c\u3001HTTP\u4e0eHTTPS<\/h3>\n<h4>2.1 \u57fa\u672c\u6982\u5ff5<\/h4>\n<table>\n<tr>\n<p>\u534f\u8bae<\/p>\n<p>\u5168\u79f0<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>HTTP\u200b<\/p>\n<\/td>\n<td>\n<p>\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae<\/p>\n<\/td>\n<td>\n<p>\u4e00\u79cd\u65e0\u72b6\u6001\u7684\u534f\u8bae&#xff0c;\u7528\u4e8e\u4f20\u8f93\u8d85\u6587\u672c&#xff08;\u5982HTML\u6587\u6863&#xff09;&#xff0c;\u5b9a\u4e49\u5ba2\u6237\u7aef\u5982\u4f55\u8bf7\u6c42\u8d44\u6e90\u4ee5\u53ca\u670d\u52a1\u5668\u5982\u4f55\u54cd\u5e94<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>HTTPS\u200b<\/p>\n<\/td>\n<td>\n<p>HTTP\u5b89\u5168\u7248<\/p>\n<\/td>\n<td>\n<p>\u5728HTTP\u57fa\u7840\u4e0a\u52a0\u5165SSL\/TLS\u5c42&#xff0c;\u63d0\u4f9b\u6570\u636e\u52a0\u5bc6\u548c\u8eab\u4efd\u9a8c\u8bc1\u529f\u80fd<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 HTTP\u4e0eHTTPS\u7684\u533a\u522b<\/h4>\n<table>\n<tr>\n<p>\u5bf9\u6bd4\u9879<\/p>\n<p>HTTP<\/p>\n<p>HTTPS<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u8bc1\u4e66\u200b<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u9700\u8981<\/p>\n<\/td>\n<td>\n<p>\u9700\u8981\u5230CA\u7533\u8bf7\u8bc1\u4e66&#xff0c;\u4e00\u822c\u514d\u8d39\u8bc1\u4e66\u8f83\u5c11<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6570\u636e\u4f20\u8f93\u200b<\/p>\n<\/td>\n<td>\n<p>\u660e\u6587\u4f20\u8f93<\/p>\n<\/td>\n<td>\n<p>SSL\u52a0\u5bc6\u4f20\u8f93<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u9ed8\u8ba4\u7aef\u53e3\u200b<\/p>\n<\/td>\n<td>\n<p>80<\/p>\n<\/td>\n<td>\n<p>443<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5b89\u5168\u6027\u200b<\/p>\n<\/td>\n<td>\n<p>\u65e0\u72b6\u6001&#xff0c;\u4e0d\u5b89\u5168<\/p>\n<\/td>\n<td>\n<p>\u52a0\u5bc6\u4f20\u8f93&#043;\u8eab\u4efd\u8ba4\u8bc1&#xff0c;\u66f4\u5b89\u5168<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e09\u3001HTTP\u72b6\u6001\u7801<\/h3>\n<h4>3.1 \u5e38\u89c1\u72b6\u6001\u7801\u901f\u67e5\u8868<\/h4>\n<table>\n<tr>\n<p>\u72b6\u6001\u7801<\/p>\n<p>\u542b\u4e49<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>200\u200b<\/p>\n<\/td>\n<td>\n<p>\u8bf7\u6c42\u6210\u529f<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u627e\u5230\u5e76\u8fd4\u56de\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u5185\u5bb9<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>301\u200b<\/p>\n<\/td>\n<td>\n<p>\u6c38\u4e45\u91cd\u5b9a\u5411<\/p>\n<\/td>\n<td>\n<p>\u8d44\u6e90\u6c38\u4e45\u8f6c\u79fb\u5230\u65b0URL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>302\u200b<\/p>\n<\/td>\n<td>\n<p>\u4e34\u65f6\u8df3\u8f6c<\/p>\n<\/td>\n<td>\n<p>URL\u4e34\u65f6\u8df3\u8f6c&#xff0c;\u975e\u6c38\u4e45\u6027<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>304\u200b<\/p>\n<\/td>\n<td>\n<p>\u4f7f\u7528\u7f13\u5b58<\/p>\n<\/td>\n<td>\n<p>\u8d44\u6e90\u672a\u4fee\u6539&#xff0c;\u5ba2\u6237\u7aef\u53ef\u4ece\u672c\u5730\u7f13\u5b58\u83b7\u53d6<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>403\u200b<\/p>\n<\/td>\n<td>\n<p>\u6743\u9650\u4e0d\u8db3<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u62d2\u7edd\u8bf7\u6c42&#xff08;\u65e0\u6743\u9650\/IP\u88ab\u5c01&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>404\u200b<\/p>\n<\/td>\n<td>\n<p>\u8d44\u6e90\u4e0d\u5b58\u5728<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u627e\u4e0d\u5230\u8bf7\u6c42\u7684\u8d44\u6e90&#xff08;\u6700\u5e38\u89c1\u9519\u8bef\u7801&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>500\u200b<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u9519\u8bef<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u7a0b\u5e8f\u672c\u8eab\u62a5\u9519<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 \u72b6\u6001\u7801\u5206\u7c7b<\/h4>\n<table>\n<tr>\n<p>\u5206\u7c7b<\/p>\n<p>\u8303\u56f4<\/p>\n<p>\u542b\u4e49<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>1xx<\/p>\n<\/td>\n<td>\n<p>100-199<\/p>\n<\/td>\n<td>\n<p>\u4fe1\u606f\u6027\u72b6\u6001\u7801<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>2xx<\/p>\n<\/td>\n<td>\n<p>200-299<\/p>\n<\/td>\n<td>\n<p>\u6210\u529f\u72b6\u6001\u7801<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>3xx<\/p>\n<\/td>\n<td>\n<p>300-399<\/p>\n<\/td>\n<td>\n<p>\u91cd\u5b9a\u5411\u72b6\u6001\u7801<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>4xx<\/p>\n<\/td>\n<td>\n<p>400-499<\/p>\n<\/td>\n<td>\n<p>\u5ba2\u6237\u7aef\u9519\u8bef\u72b6\u6001\u7801<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>5xx<\/p>\n<\/td>\n<td>\n<p>500-599<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u5668\u9519\u8bef\u72b6\u6001\u7801<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u56db\u3001\u539f\u751fXMLHttpRequest\u53d1\u9001GET\u8bf7\u6c42<\/h3>\n<h4>4.1 \u57fa\u672c\u6b65\u9aa4<\/h4>\n<p>\/\/ \u7ed1\u5b9a\u4e8b\u4ef6<br \/>\nbtn.onclick &#061; function() {<br \/>\n    \/\/ 1. \u521b\u5efa\u5bf9\u8c61<br \/>\n    const xhr &#061; new XMLHttpRequest();<\/p>\n<p>    \/\/ 2. \u521d\u59cb\u5316&#xff1a;\u8bbe\u7f6e\u8bf7\u6c42\u65b9\u6cd5\u548cURL&#xff08;\u53ef\u52a0\u53c2\u6570&#xff09;<br \/>\n    xhr.open(&#034;GET&#034;, &#034;http:\/\/127.0.0.1:8000\/server?a&#061;100&amp;b&#061;200&amp;c&#061;300&#034;);<\/p>\n<p>    \/\/ 3. \u53d1\u9001<br \/>\n    xhr.send();<\/p>\n<p>    \/\/ 4. \u4e8b\u4ef6\u7ed1\u5b9a&#xff1a;\u5904\u7406\u670d\u52a1\u7aef\u8fd4\u56de\u7684\u7ed3\u679c<br \/>\n    xhr.onreadystatechange &#061; function() {<br \/>\n        \/\/ \u5224\u65ad\u670d\u52a1\u7aef\u8fd4\u56de\u4e86\u6240\u6709\u7ed3\u679c<br \/>\n        if (xhr.readyState &#061;&#061;&#061; 4) {<br \/>\n            \/\/ \u5224\u65ad\u54cd\u5e94\u72b6\u6001\u7801&#xff08;2xx\u8868\u793a\u6210\u529f&#xff09;<br \/>\n            if (xhr.status &gt;&#061; 200 &amp;&amp; xhr.status &lt; 300) {<br \/>\n                \/\/ \u5904\u7406\u7ed3\u679c&#xff1a;\u54cd\u5e94\u884c\u3001\u54cd\u5e94\u5934\u3001\u54cd\u5e94\u4f53<br \/>\n                result.innerHTML &#061; xhr.response;<br \/>\n            }<br \/>\n        }<br \/>\n    };<br \/>\n}; <\/p>\n<h4>4.2 \u4e8b\u4ef6\u76d1\u542c\u5904\u7406\u54cd\u5e94\u7ed3\u679c<\/h4>\n<p>xhr.onreadystatechange &#061; function() {<br \/>\n    if (xhr.readyState &#061;&#061;&#061; 4) {          \/\/ \u8bf7\u6c42\u5b8c\u6210<br \/>\n        if (xhr.status &gt;&#061; 200 &amp;&amp; xhr.status &lt; 300) {  \/\/ \u8bf7\u6c42\u6210\u529f<br \/>\n            \/\/ \u5904\u7406\u670d\u52a1\u5668\u8fd4\u56de\u7684\u7ed3\u679c<br \/>\n            console.log(xhr.response);<br \/>\n        }<br \/>\n    }<br \/>\n}; <\/p>\n<h4>4.3 readyState\u72b6\u6001\u8bf4\u660e<\/h4>\n<table>\n<tr>\n<p>\u72b6\u6001\u503c<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>0\u200b<\/p>\n<\/td>\n<td>\n<p>\u521d\u59cb\u5316\u72b6\u6001&#xff0c;XMLHttpRequest\u5bf9\u8c61\u5df2\u521b\u5efa<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>1\u200b<\/p>\n<\/td>\n<td>\n<p>open()\u65b9\u6cd5\u5df2\u8c03\u7528&#xff0c;\u8bf7\u6c42\u5df2\u521d\u59cb\u5316<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>2\u200b<\/p>\n<\/td>\n<td>\n<p>send()\u65b9\u6cd5\u5df2\u8c03\u7528&#xff0c;\u8bf7\u6c42\u5df2\u53d1\u9001<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>3\u200b<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u7aef\u8fd4\u56de\u90e8\u5206\u7ed3\u679c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>4\u200b<\/p>\n<\/td>\n<td>\n<p>\u670d\u52a1\u7aef\u8fd4\u56de\u6240\u6709\u7ed3\u679c&#xff0c;\u8bf7\u6c42\u5b8c\u6210<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.4 \u54cd\u5e94\u7ed3\u679c\u5904\u7406<\/h4>\n<p>xhr.onreadystatechange &#061; function() {<br \/>\n    if (xhr.readyState &#061;&#061;&#061; 4) {<br \/>\n        if (xhr.status &gt;&#061; 200 &amp;&amp; xhr.status &lt; 300) {<br \/>\n            \/\/ \u54cd\u5e94\u884c<br \/>\n            console.log(xhr.status);          \/\/ \u72b6\u6001\u7801<br \/>\n            console.log(xhr.statusText);      \/\/ \u72b6\u6001\u5b57\u7b26\u4e32<\/p>\n<p>            \/\/ \u54cd\u5e94\u5934<br \/>\n            console.log(xhr.getAllResponseHeaders());  \/\/ \u6240\u6709\u54cd\u5e94\u5934<\/p>\n<p>            \/\/ \u54cd\u5e94\u4f53<br \/>\n            console.log(xhr.response);        \/\/ \u54cd\u5e94\u4f53\u5185\u5bb9<br \/>\n            result.innerHTML &#061; xhr.response;  \/\/ \u8bbe\u7f6e\u9875\u9762\u5185\u5bb9<br \/>\n        }<br \/>\n    }<br \/>\n}; <\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4f7f\u7528axios\u53d1\u9001AJAX\u8bf7\u6c42<\/h3>\n<h4>5.1 \u4e09\u79cd\u5904\u7406\u5f02\u6b65\u7ed3\u679c\u7684\u65b9\u5f0f<\/h4>\n<h5>\u65b9\u5f0f\u4e00&#xff1a;\u56de\u8c03\u51fd\u6570<\/h5>\n<p>axios.get(&#034;http:\/\/localhost:3002\/user&#034;).then(<br \/>\n    \/\/ \u6210\u529f\u56de\u8c03<br \/>\n    (res) &#061;&gt; {<br \/>\n        console.log(res.data);<br \/>\n    },<br \/>\n    \/\/ \u5931\u8d25\u56de\u8c03<br \/>\n    (err) &#061;&gt; {<br \/>\n        console.log(err);<br \/>\n    }<br \/>\n); <\/p>\n<h5>\u65b9\u5f0f\u4e8c&#xff1a;\u94fe\u5f0f\u8c03\u7528<\/h5>\n<p>axios.get(&#034;http:\/\/localhost:3002\/user&#034;)<br \/>\n    .then((res) &#061;&gt; {<br \/>\n        \/\/ \u5904\u7406\u6210\u529f<br \/>\n        console.log(res.data);<br \/>\n    })<br \/>\n    .catch((err) &#061;&gt; {<br \/>\n        \/\/ \u6355\u83b7\u5931\u8d25<br \/>\n        console.log(err.message);<br \/>\n    }); <\/p>\n<h5>\u65b9\u5f0f\u4e09&#xff1a;async\/await&#xff08;ES6\u63a8\u8350&#xff09;<\/h5>\n<p>async function getData() {<br \/>\n    try {<br \/>\n        let res &#061; await axios.get(&#034;http:\/\/localhost:3002\/user&#034;);<br \/>\n        console.log(res.data);<br \/>\n    } catch (error) {<br \/>\n        console.log(error);<br \/>\n    }<br \/>\n} <\/p>\n<h4>5.2 \u4e09\u79cd\u65b9\u5f0f\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\n<p>\u65b9\u5f0f<\/p>\n<p>\u4f18\u70b9<\/p>\n<p>\u7f3a\u70b9<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u56de\u8c03\u200b<\/p>\n<\/td>\n<td>\n<p>\u7b80\u5355\u76f4\u89c2<\/p>\n<\/td>\n<td>\n<p>\u56de\u8c03\u5730\u72f1&#xff0c;\u4ee3\u7801\u5d4c\u5957\u6df1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u94fe\u5f0f\u8c03\u7528\u200b<\/p>\n<\/td>\n<td>\n<p>\u4ee3\u7801\u6241\u5e73&#xff0c;\u6613\u8bfb<\/p>\n<\/td>\n<td>\n<p>\u4ecd\u9700.then\/.catch<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>async\/await\u200b<\/p>\n<\/td>\n<td>\n<p>\u6700\u63a5\u8fd1\u540c\u6b65\u4ee3\u7801&#xff0c;\u63a8\u8350<\/p>\n<\/td>\n<td>\n<p>\u9700\u914d\u5408try\/catch<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001axios GET\u8bf7\u6c42\u53c2\u6570\u4f20\u9012<\/h3>\n<h4>6.1 URL\u76f4\u63a5\u4f20\u53c2<\/h4>\n<p>\/\/ \u76f4\u63a5\u5728URL\u4e2d\u6dfb\u52a0\u67e5\u8be2\u53c2\u6570<br \/>\nlet res &#061; await axios.get(&#034;http:\/\/localhost:3001\/list?name&#061;\u5b59\u609f\u7a7a&#034;); <\/p>\n<h4>6.2 \u4f7f\u7528params\u5bf9\u8c61\u4f20\u53c2&#xff08;\u63a8\u8350&#xff09;<\/h4>\n<p>let res &#061; await axios.get(&#034;http:\/\/localhost:3001\/list&#034;, {<br \/>\n    params: {   \/\/ params\u4e3a\u56fa\u5b9a\u5c5e\u6027\u540d<br \/>\n        id: 4<br \/>\n    }<br \/>\n}); <\/p>\n<h4>6.3 \u4e24\u79cd\u65b9\u5f0f\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\n<p>\u65b9\u5f0f<\/p>\n<p>\u5199\u6cd5<\/p>\n<p>\u9002\u7528\u573a\u666f<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>URL\u62fc\u63a5\u200b<\/p>\n<\/td>\n<td>\n<p>?key&#061;value<\/p>\n<\/td>\n<td>\n<p>\u53c2\u6570\u5c11\u4e14\u7b80\u5355<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>params\u5bf9\u8c61\u200b<\/p>\n<\/td>\n<td>\n<p>{params: {key: value}}<\/p>\n<\/td>\n<td>\n<p>\u53c2\u6570\u591a\u6216\u52a8\u6001\u751f\u6210<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e03\u3001\u6570\u636e\u6e32\u67d3\u5b9e\u6218\u6848\u4f8b<\/h3>\n<h4>7.1 \u7c7b\u5c01\u88c5\u5b9e\u73b0\u6570\u636e\u83b7\u53d6\u548c\u6e32\u67d3<\/h4>\n<p>class DataRenderer {<br \/>\n    constructor(url, containerSelector) {<br \/>\n        this.url &#061; url;<br \/>\n        this.container &#061; document.querySelector(containerSelector);<br \/>\n        this.init();<br \/>\n    }<\/p>\n<p>    async init() {<br \/>\n        try {<br \/>\n            const data &#061; await this.fetchData();<br \/>\n            this.render(data);<br \/>\n        } catch (error) {<br \/>\n            console.error(&#039;\u6570\u636e\u83b7\u53d6\u5931\u8d25:&#039;, error);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    async fetchData() {<br \/>\n        const response &#061; await axios.get(this.url);<br \/>\n        return response.data;<br \/>\n    }<\/p>\n<p>    render(data) {<br \/>\n        \/\/ \u6839\u636e\u6570\u636e\u7ed3\u6784\u6e32\u67d3\u5230\u9875\u9762<br \/>\n        this.container.innerHTML &#061; &#096;<br \/>\n            &lt;h3&gt;${data.name}&lt;\/h3&gt;<br \/>\n            &lt;p&gt;\u5e74\u9f84: ${data.age}&lt;\/p&gt;<br \/>\n            &lt;p&gt;\u6027\u522b: ${data.sex}&lt;\/p&gt;<br \/>\n            &lt;p&gt;\u5730\u5740: ${data.address}&lt;\/p&gt;<br \/>\n        &#096;;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u4f7f\u7528\u793a\u4f8b<br \/>\nconst renderer &#061; new DataRenderer(<br \/>\n    &#039;http:\/\/localhost:3002\/user&#039;,<br \/>\n    &#039;#app&#039;<br \/>\n); <\/p>\n<hr \/>\n<h3>\u516b\u3001JSON Server\u914d\u7f6e\u8bf4\u660e<\/h3>\n<h4>8.1 \u4ec0\u4e48\u662fJSON Server<\/h4>\n<p>json-server\u200b \u662f\u4e00\u4e2a\u80fd\u8ba9\u524d\u7aef\u4eba\u5458\u5728\u672c\u5730\u642d\u5efaJSON\u670d\u52a1\u7684\u5de5\u5177&#xff0c;\u7528\u4e8e\u6a21\u62df\u540e\u7aef\u6570\u636e\u63a5\u53e3\u3002<\/p>\n<table>\n<tr>\n<p>\u7279\u6027<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u4e3b\u8981\u7528\u9014\u200b<\/p>\n<\/td>\n<td>\n<p>\u524d\u540e\u7aef\u5206\u79bb\u5f00\u53d1\u65f6&#xff0c;\u524d\u7aef\u5148\u884c\u6a21\u62df\u6570\u636e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5de5\u4f5c\u6d41\u7a0b\u200b<\/p>\n<\/td>\n<td>\n<p>\u540e\u7aef\u63a5\u53e3\u672a\u5f00\u53d1\u597d \u2192 \u524d\u7aef\u7528json-server\u6a21\u62df \u2192 \u540e\u7aef\u63a5\u53e3\u5f00\u53d1\u597d\u540e\u66ff\u6362URL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8de8\u5e73\u53f0\u200b<\/p>\n<\/td>\n<td>\n<p>\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u5373\u53ef\u5728\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u7b80\u5355\u6613\u7528\u200b<\/p>\n<\/td>\n<td>\n<p>\u53ea\u9700\u8bbf\u95ee\u7279\u5b9aURL\u5373\u53ef\u67e5\u770b\u6570\u636e\u5217\u8868\u5e76\u5f00\u59cb\u901a\u4fe1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>GitHub\u5730\u5740&#xff1a;GitHub &#8211; typicode\/json-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously) \u00b7 GitHub<\/p>\n<p>npm\u5730\u5740&#xff1a;https:\/\/www.npmjs.com\/package\/json-server<\/p>\n<h4>8.2 \u529f\u80fd\u7279\u6027<\/h4>\n<table>\n<tr>\n<p>\u7279\u6027<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u8de8\u5e73\u53f0\u517c\u5bb9<\/p>\n<\/td>\n<td>\n<p>\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u5373\u53ef\u5728\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u7b80\u5355\u6613\u7528<\/p>\n<\/td>\n<td>\n<p>\u53ea\u9700\u8bbf\u95ee\u7279\u5b9aURL&#xff0c;\u5373\u53ef\u67e5\u770b\u6570\u636e\u5217\u8868\u5e76\u5f00\u59cb\u901a\u4fe1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5b89\u5168\u53ef\u9760<\/p>\n<\/td>\n<td>\n<p>\u5141\u8bb8\u901a\u8fc7\u9632\u706b\u5899\u8bbe\u7f6e&#xff0c;\u53ea\u5f00\u653e\u6307\u5b9a\u7684\u7aef\u53e3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Websocket\u4e00\u4f53\u5316<\/p>\n<\/td>\n<td>\n<p>\u5185\u7f6eWeb\u670d\u52a1\u5668&#xff0c;\u652f\u6301WebSocket\u8fde\u63a5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6613\u4e8e\u96c6\u6210<\/p>\n<\/td>\n<td>\n<p>\u901a\u8fc7JSON\u683c\u5f0f\u4ea4\u6362\u6570\u636e&#xff0c;\u4fbf\u4e8e\u524d\u540e\u7aef\u5f00\u53d1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u9ad8\u7ea7\u529f\u80fd<\/p>\n<\/td>\n<td>\n<p>\u652f\u6301\u8de8\u57df\u3001jsonp\u3001\u8def\u7531\u8ba2\u5236\u3001\u6570\u636e\u5feb\u7167\u4fdd\u5b58\u7b49<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>8.3 package.json\u811a\u672c\u914d\u7f6e<\/h4>\n<p>{<br \/>\n    &#034;scripts&#034;: {<br \/>\n        &#034;index&#034;: &#034;json-server &#8211;watch index.json &#8211;port 3001&#034;,<br \/>\n        &#034;db&#034;: &#034;json-server &#8211;watch db.json &#8211;port 3002&#034;,<br \/>\n        &#034;all&#034;: &#034;concurrently \\\\&#034;npm run index\\\\&#034; \\\\&#034;npm run db\\\\&#034;&#034;<br \/>\n    }<br \/>\n} <\/p>\n<table>\n<tr>\n<p>\u547d\u4ee4<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>npm run index<\/p>\n<\/td>\n<td>\n<p>\u542f\u52a8\u5217\u8868\u6570\u636e\u670d\u52a1&#xff08;\u7aef\u53e33001&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>npm run db<\/p>\n<\/td>\n<td>\n<p>\u542f\u52a8\u7528\u6237\u6570\u636e\u670d\u52a1&#xff08;\u7aef\u53e33002&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>npm run all<\/p>\n<\/td>\n<td>\n<p>\u540c\u65f6\u542f\u52a8\u4e24\u4e2a\u670d\u52a1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>8.4 \u6570\u636e\u6587\u4ef6\u7ed3\u6784<\/h4>\n<h5>\u7528\u6237\u6570\u636e&#xff08;db.json&#xff09;<\/h5>\n<p>{<br \/>\n    &#034;user&#034;: {<br \/>\n        &#034;name&#034;: &#034;jack&#034;,<br \/>\n        &#034;age&#034;: 18,<br \/>\n        &#034;sex&#034;: &#034;\u7537&#034;,<br \/>\n        &#034;address&#034;: &#034;\u5408\u80a5&#034;<br \/>\n    }<br \/>\n} <\/p>\n<h5>\u5217\u8868\u6570\u636e&#xff08;index.json&#xff09;<\/h5>\n<p>{<br \/>\n    &#034;list&#034;: [<br \/>\n        {<br \/>\n            &#034;id&#034;: &#034;1&#034;,<br \/>\n            &#034;name&#034;: &#034;\u5510\u50e7&#034;,<br \/>\n            &#034;age&#034;: 20,<br \/>\n            &#034;address&#034;: &#034;\u4e1c\u571f\u5927\u5510&#034;<br \/>\n        }<br \/>\n    ]<br \/>\n} <\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u5173\u952e\u77e5\u8bc6\u70b9\u603b\u7ed3<\/h3>\n<h4>9.1 \u6280\u672f\u6808\u901f\u67e5\u8868<\/h4>\n<table>\n<tr>\n<p>\u6280\u672f<\/p>\n<p>\u8bf4\u660e<\/p>\n<p>\u9002\u7528\u573a\u666f<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>XMLHttpRequest\u200b<\/p>\n<\/td>\n<td>\n<p>\u6d4f\u89c8\u5668\u539f\u751fAJAX API<\/p>\n<\/td>\n<td>\n<p>\u9700\u8981\u624b\u52a8\u63a7\u5236\u8bf7\u6c42\u7ec6\u8282<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>axios\u200b<\/p>\n<\/td>\n<td>\n<p>\u57fa\u4e8ePromise\u7684HTTP\u5ba2\u6237\u7aef<\/p>\n<\/td>\n<td>\n<p>\u7b80\u5316\u5f02\u6b65\u8bf7\u6c42\u5904\u7406<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>async\/await\u200b<\/p>\n<\/td>\n<td>\n<p>ES6\u5f02\u6b65\u7f16\u7a0b\u89e3\u51b3\u65b9\u6848<\/p>\n<\/td>\n<td>\n<p>\u4f7f\u5f02\u6b65\u4ee3\u7801\u66f4\u6e05\u6670\u6613\u8bfb<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>JSON Server\u200b<\/p>\n<\/td>\n<td>\n<p>REST API\u6a21\u62df\u670d\u52a1\u5668<\/p>\n<\/td>\n<td>\n<p>\u524d\u7aef\u5f00\u53d1\u65f6\u6a21\u62df\u540e\u7aef\u63a5\u53e3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>9.2 \u6ce8\u610f\u4e8b\u9879<\/h4>\n<table>\n<tr>\n<p>\u6ce8\u610f\u4e8b\u9879<\/p>\n<p>\u8bf4\u660e<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u54cd\u5e94\u6570\u636e\u5904\u7406\u200b<\/p>\n<\/td>\n<td>\n<p>\u6ce8\u610fJSON\u5b57\u7b26\u4e32\u4e0eJavaScript\u5bf9\u8c61\u7684\u8f6c\u6362<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8de8\u57df\u95ee\u9898\u200b<\/p>\n<\/td>\n<td>\n<p>\u751f\u4ea7\u73af\u5883\u9700\u540e\u7aef\u914d\u7f6eCORS\u6216\u4f7f\u7528\u4ee3\u7406<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8bf7\u6c42\u9519\u8bef\u5904\u7406\u200b<\/p>\n<\/td>\n<td>\n<p>\u59cb\u7ec8\u4f7f\u7528try\/catch\u6216.catch()\u5904\u7406\u9519\u8bef<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>URL\u66ff\u6362\u200b<\/p>\n<\/td>\n<td>\n<p>\u540e\u7aef\u63a5\u53e3\u5f00\u53d1\u597d\u540e&#xff0c;\u66ff\u6362json-server\u7684URL<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u7cfb\u7edf\u68b3\u7406\u4e86AJAX\u7b2c\u4e00\u90e8\u5206\u7684\u5b8c\u6574\u77e5\u8bc6\u4f53\u7cfb&#xff1a;<\/p>\n<table>\n<tr>\n<p>\u4e3b\u9898<\/p>\n<p>\u6838\u5fc3\u8981\u70b9<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>AJAX\u57fa\u7840\u200b<\/p>\n<\/td>\n<td>\n<p>\u5f02\u6b65\u8bf7\u6c42\u3001\u65e0\u5237\u65b0\u66f4\u65b0\u3001\u4f18\u7f3a\u70b9<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>HTTP\/HTTPS\u200b<\/p>\n<\/td>\n<td>\n<p>\u534f\u8bae\u533a\u522b\u3001\u7aef\u53e3\u5dee\u5f02\u3001\u5b89\u5168\u6027<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u72b6\u6001\u7801\u200b<\/p>\n<\/td>\n<td>\n<p>200\u6210\u529f\u3001301\/302\u91cd\u5b9a\u5411\u3001304\u7f13\u5b58\u3001403\/404\/500\u9519\u8bef<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u539f\u751fXHR\u200b<\/p>\n<\/td>\n<td>\n<p>\u521b\u5efa\u5bf9\u8c61\u3001open\/send\u3001readyState\u3001status\u5224\u65ad<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>axios\u200b<\/p>\n<\/td>\n<td>\n<p>\u56de\u8c03\/\u94fe\u5f0f\/async-await\u4e09\u79cd\u65b9\u5f0f\u3001params\u4f20\u53c2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>JSON Server\u200b<\/p>\n<\/td>\n<td>\n<p>\u5b89\u88c5\u914d\u7f6e\u3001\u6570\u636e\u6587\u4ef6\u7ed3\u6784\u3001\u591a\u7aef\u53e3\u542f\u52a8<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9&#xff0c;\u4f60\u5c31\u5177\u5907\u4e86\u524d\u540e\u7aef\u6570\u636e\u4ea4\u4e92\u7684\u5b8c\u6574\u80fd\u529b\u3002\u4e0b\u4e00\u7bc7\u5c06\u7ee7\u7eed\u6df1\u5165AJAX\u7684\u9ad8\u7ea7\u5e94\u7528&#xff0c;\u6b22\u8fce\u6301\u7eed\u5173\u6ce8&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\nAJAX\u662f\u73b0\u4ee3\u524d\u7aef\u5f00\u53d1\u4e2d\u4e0e\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u4eceAJAX\u57fa\u7840\u6982\u5ff5\u8bb2\u8d77&#xff0c;\u7cfb\u7edf\u8bb2\u89e3HTTP\u534f\u8bae\u3001\u539f\u751fXMLHttpRequest\u53d1\u9001GET\u8bf7\u6c42\u3001axios\u5e93\u7684\u4f7f\u7528\u3001GET\u8bf7\u6c42\u53c2\u6570\u4f20\u9012\u3001\u6570\u636e\u6e32\u67d3\u5b9e\u6218\u4ee5\u53caJSON Server\u642d\u5efa\u6a21\u62df\u63a5\u53e3\u3002\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9&#xff0c;\u4f60\u5c06\u5177\u5907\u5b8c\u6574\u7684\u524d\u540e\u7aef\u6570\u636e\u4ea4\u4e92\u80fd\u529b\u3002 \u4e00\u3001\u539f\u751fAJAX\u4ecb\u7ecd<br \/>\n1.1 \u4ec0\u4e48\u662fAJAX<br \/>\nAJAX\u5168\u79f0\u4e3a Asynchronous JavaScript And XML&#xff08;\u5f02\u6b65\u7684JS<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2390],"topic":[],"class_list":["post-101550","post","type-post","status-publish","format-standard","hentry","category-server","tag-okhttp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/101550.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 AJAX\u662f\u73b0\u4ee3\u524d\u7aef\u5f00\u53d1\u4e2d\u4e0e\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u4eceAJAX\u57fa\u7840\u6982\u5ff5\u8bb2\u8d77&#xff0c;\u7cfb\u7edf\u8bb2\u89e3HTTP\u534f\u8bae\u3001\u539f\u751fXMLHttpRequest\u53d1\u9001GET\u8bf7\u6c42\u3001axios\u5e93\u7684\u4f7f\u7528\u3001GET\u8bf7\u6c42\u53c2\u6570\u4f20\u9012\u3001\u6570\u636e\u6e32\u67d3\u5b9e\u6218\u4ee5\u53caJSON Server\u642d\u5efa\u6a21\u62df\u63a5\u53e3\u3002\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9&#xff0c;\u4f60\u5c06\u5177\u5907\u5b8c\u6574\u7684\u524d\u540e\u7aef\u6570\u636e\u4ea4\u4e92\u80fd\u529b\u3002 \u4e00\u3001\u539f\u751fAJAX\u4ecb\u7ecd 1.1 \u4ec0\u4e48\u662fAJAX AJAX\u5168\u79f0\u4e3a Asynchronous JavaScript And XML&#xff08;\u5f02\u6b65\u7684JS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/101550.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-06T16:36:31+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101550.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/101550.html\",\"name\":\"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-06T16:36:31+00:00\",\"dateModified\":\"2026-09-06T16:36:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/101550.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/101550.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101550.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/101550.html","og_locale":"zh_CN","og_type":"article","og_title":"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 AJAX\u662f\u73b0\u4ee3\u524d\u7aef\u5f00\u53d1\u4e2d\u4e0e\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u4eceAJAX\u57fa\u7840\u6982\u5ff5\u8bb2\u8d77&#xff0c;\u7cfb\u7edf\u8bb2\u89e3HTTP\u534f\u8bae\u3001\u539f\u751fXMLHttpRequest\u53d1\u9001GET\u8bf7\u6c42\u3001axios\u5e93\u7684\u4f7f\u7528\u3001GET\u8bf7\u6c42\u53c2\u6570\u4f20\u9012\u3001\u6570\u636e\u6e32\u67d3\u5b9e\u6218\u4ee5\u53caJSON Server\u642d\u5efa\u6a21\u62df\u63a5\u53e3\u3002\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9&#xff0c;\u4f60\u5c06\u5177\u5907\u5b8c\u6574\u7684\u524d\u540e\u7aef\u6570\u636e\u4ea4\u4e92\u80fd\u529b\u3002 \u4e00\u3001\u539f\u751fAJAX\u4ecb\u7ecd 1.1 \u4ec0\u4e48\u662fAJAX AJAX\u5168\u79f0\u4e3a Asynchronous JavaScript And XML&#xff08;\u5f02\u6b65\u7684JS","og_url":"https:\/\/www.wsisp.com\/helps\/101550.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-06T16:36:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/101550.html","url":"https:\/\/www.wsisp.com\/helps\/101550.html","name":"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-06T16:36:31+00:00","dateModified":"2026-09-06T16:36:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/101550.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/101550.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/101550.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"JS AJAX\u5b8c\u5168\u6307\u5357\uff08\u4e00\uff09\uff1a\u4ece\u539f\u751fXHR\u5230axios\uff0c\u518d\u5230JSON Server\u6a21\u62df\u6570\u636e"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=101550"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101550\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=101550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=101550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=101550"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=101550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}