{"id":31099,"date":"2024-11-25T14:09:12","date_gmt":"2024-11-25T06:09:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31099\/"},"modified":"2024-11-25T14:09:12","modified_gmt":"2024-11-25T06:09:12","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8fajax%e5%ae%9e%e7%8e%b0%e8%af%b7%e6%b1%82%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%95%b0%e6%8d%ae%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31099\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b"},"content":{"rendered":"<p>\u6628\u5929\u4e0b\u8f7d\u4e86\u4e00\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u5927\u6982\u770b\u4e86\u4e00\u4e0b\u6587\u6863\uff0c\u7b80\u5355\u7684\u7528\u4ed6\u7684\u65b9\u6cd5\u5b9e\u73b0\u4e86ajax\u8bf7\u6c42\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u53ca\u6a21\u7248\u904d\u5386\u6570\u636e\u529f\u80fd,\u7ed3\u5408\u5b9e\u4f8b\u5f62\u5f0f\u5206\u6790\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u8c03\u7528\u53ca\u6a21\u677fwx:for\u5faa\u73af\u5217\u8868\u6e32\u67d3\u76f8\u5173\u64cd\u4f5c\u6280\u5de7,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/a978f22ed6b1b1294e243b1758605a45-0.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5934\u90e8\u6807\u9898\u548c\u5e95\u90e8tab\u914d\u7f6e\u90fd\u5728 app.json\u6587\u4ef6\u4e2d\uff0c\u5e95\u90e8tab\u4f4d\u6700\u5c11\u4e24\u4e2a\uff0c\u6700\u591a\u4e94\u4e2a<\/strong>\u3002\u4e0b\u9762\u662fapp.json\u6587\u4ef6\u4ee3\u7801\u548c\u76f8\u5173\u6ce8\u91ca<\/p>\n<p><\/p>\n<pre>{\r\n&nbsp;\"pages\":[\r\n&nbsp;&nbsp;\"pages\/index\/index\",\r\n&nbsp;&nbsp;\"pages\/tucao\/tucao\",\r\n&nbsp;&nbsp;\"pages\/center\/center\"\r\n&nbsp;],\r\n&nbsp;\"window\":{\r\n&nbsp;&nbsp;\"backgroundTextStyle\":\"\",\r\n&nbsp;&nbsp;\"navigationBarBackgroundColor\":&nbsp;\"red\",\r\n&nbsp;&nbsp;\"navigationBarTitleText\":&nbsp;\"\u4e00\u4e2a\u6807\u9898\u800c\u5df2\",\r\n&nbsp;&nbsp;\"navigationBarTextStyle\":\"white\"\r\n&nbsp;},\r\n&nbsp;\"tabBar\":&nbsp;{\r\n&nbsp;&nbsp;\"list\":&nbsp;[{\r\n&nbsp;&nbsp;&nbsp;\"pagePath\":&nbsp;\"pages\/index\/index\",\r\n&nbsp;&nbsp;&nbsp;\"text\":&nbsp;\"\u9996\u9875\",\r\n&nbsp;&nbsp;&nbsp;\"iconPath\":&nbsp;\"\/images\/public\/menu-cd.png\",\r\n&nbsp;&nbsp;&nbsp;\"selectedIconPath\":&nbsp;\"\/images\/public\/menu.png\"\r\n&nbsp;&nbsp;},{\r\n&nbsp;&nbsp;&nbsp;\"pagePath\":&nbsp;\"pages\/tucao\/tucao\",\r\n&nbsp;&nbsp;&nbsp;\"text\":&nbsp;\"\u5410\u69fd\",\r\n&nbsp;&nbsp;&nbsp;\"iconPath\":&nbsp;\"\/images\/public\/hot-cd.png\",\r\n&nbsp;&nbsp;&nbsp;\"selectedIconPath\":&nbsp;\"\/images\/public\/hot.png\"\r\n&nbsp;&nbsp;},{\r\n&nbsp;&nbsp;&nbsp;\"pagePath\":&nbsp;\"pages\/center\/center\",\r\n&nbsp;&nbsp;&nbsp;\"text\":&nbsp;\"\u6211\u7684\",\r\n&nbsp;&nbsp;&nbsp;\"iconPath\":&nbsp;\"\/images\/public\/center-cd.png\",\r\n&nbsp;&nbsp;&nbsp;\"selectedIconPath\":&nbsp;\"\/images\/public\/center.png\"\r\n&nbsp;&nbsp;}],\r\n&nbsp;&nbsp;\"borderStyle\":&nbsp;\"white\"\r\n&nbsp;}\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\u6211\u662f\u901a\u8fc7 \u5fae\u4fe1\u5c0f\u7a0b\u5e8fwx.request\u5b9e\u73b0ajax\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u7684\uff0c\u4e00\u4e2a\u7a0b\u5e8f\u91cc\u9762\u6700\u591a\u80fd\u6709\u4e94\u4e2a\u8fd9\u6837\u7684\u8bf7\u6c42\u3002\u4e0b\u9762\u662findex.js\u7684\u4ee3\u7801<\/p>\n<p><\/p>\n<pre>\/\/index.js\r\n\/\/\u83b7\u53d6\u5e94\u7528\u5b9e\u4f8b\r\nvar&nbsp;app&nbsp;=&nbsp;getApp()\r\nPage({\r\n&nbsp;data:&nbsp;{\r\n&nbsp;&nbsp;motto:&nbsp;'Hello&nbsp;World',\r\n&nbsp;&nbsp;userInfo:&nbsp;{},\r\n&nbsp;&nbsp;Industry:{}\r\n&nbsp;},\r\n&nbsp;onLoad:&nbsp;function&nbsp;(res)&nbsp;{\r\n&nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this\r\n&nbsp;&nbsp;\/\/\u8c03\u7528\u5e94\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u83b7\u53d6\u5168\u5c40\u6570\u636e\r\n&nbsp;&nbsp;app.getUserInfo(function(userInfo){\r\n&nbsp;&nbsp;&nbsp;\/\/\u66f4\u65b0\u6570\u636e\r\n&nbsp;&nbsp;&nbsp;that.setData({\r\n&nbsp;&nbsp;&nbsp;&nbsp;userInfo:userInfo\r\n&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;})\r\n&nbsp;&nbsp;wx.request({\r\n&nbsp;&nbsp;&nbsp;url:&nbsp;'http:\/\/xx.xxxxx.com\/xxx.php',\/\/\u4e0a\u7ebf\u7684\u8bdd\u5fc5\u987b\u662fhttps\uff0c\u6ca1\u6709appId\u7684\u672c\u5730\u8bf7\u6c42\u8c8c\u4f3c\u4e0d\u53d7\u5f71\u54cd\r\n&nbsp;&nbsp;&nbsp;data:&nbsp;{},\r\n&nbsp;&nbsp;&nbsp;method:&nbsp;'GET',&nbsp;\/\/&nbsp;OPTIONS,&nbsp;GET,&nbsp;HEAD,&nbsp;POST,&nbsp;PUT,&nbsp;DELETE,&nbsp;TRACE,&nbsp;CONNECT\r\n&nbsp;&nbsp;&nbsp;\/\/&nbsp;header:&nbsp;{},&nbsp;\/\/&nbsp;\u8bbe\u7f6e\u8bf7\u6c42\u7684&nbsp;header\r\n&nbsp;&nbsp;&nbsp;success:&nbsp;function(res){\r\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(res.data.result)\r\n&nbsp;&nbsp;&nbsp;&nbsp;that.setData({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Industry:res.data.result\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;fail:&nbsp;function()&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;fail\r\n&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;complete:&nbsp;function()&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;complete\r\n&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;})\r\n&nbsp;}\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2dhttp:\/\/xx.xxxxx.com\/xxx.php\u7684\u8fd4\u56de\u6570\u636e\u683c\u5f0f\u662f\u4e00\u4e2ajson\uff0c\u683c\u5f0f\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/57d436b006ea05ccae7d6ac2a6db4114-1.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b\u63d2\u56fe1\" \/><\/p>\n<p>\u5c55\u793a\u9875\u9762\u5c31\u7b80\u5355\u4e86\uff0c\u53d8\u91cf<span style=\"color: #0000ff\">{{array}}<\/span> \u5fae\u4fe1\u6a21\u7248\u904d\u5386\u6570\u636e\u4f7f\u7528 wx:for \u3002index.wxml\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!--index.wxml--&gt;\r\n&lt;view&gt;\r\n&nbsp;&lt;view&gt;\r\n&nbsp;&nbsp;&lt;image&gt;&lt;\/image&gt;\r\n&nbsp;&nbsp;&lt;text&gt;{{userInfo.nickName}}&lt;\/text&gt;\r\n&nbsp;&lt;\/view&gt;&lt;\/view&gt;&lt;view&gt;\r\n&nbsp;&nbsp;{{index}}\uff1a{{item.name}}\r\n&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u5b9e\u4f8b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u5929\u4e0b\u8f7d\u4e86\u4e00\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u5927\u6982\u770b\u4e86\u4e00\u4e0b\u6587\u6863\uff0c\u7b80\u5355\u7684\u7528\u4ed6\u7684\u65b9\u6cd5\u5b9e\u73b0\u4e86ajax\u8bf7\u6c42\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u5b9e\u73b0\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u53ca\u6a21\u7248\u904d\u5386\u6570\u636e\u529f\u80fd,\u7ed3\u5408\u5b9e\u4f8b\u5f62\u5f0f\u5206\u6790\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8fajax\u8c03\u7528\u53ca\u6a21\u677fwx:for\u5faa\u73af\u5217\u8868\u6e32\u67d3\u76f8\u5173\u64cd\u4f5c\u6280\u5de7,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002 \u5934\u90e8\u6807\u9898\u548c\u5e95\u90e8tab\u914d\u7f6e\u90fd\u5728 app.json\u6587\u4ef6\u4e2d\uff0c\u5e95\u90e8tab\u4f4d\u6700\u5c11\u4e24\u4e2a\uff0c\u6700\u591a\u4e94\u4e2a\u3002\u4e0b\u9762\u662fapp.json\u6587\u4ef6\u4ee3\u7801\u548c\u76f8\u5173\u6ce8\u91ca { &nbsp;&#8220;pages&#8221;:[ &nbsp;&nbsp;&#8220;pages\/index\/index&#8221;, &nbsp;&nbsp;&#8220;pages\/tucao\/tucao&#8221;, &nbsp;&nbsp;&#8220;pages\/center\/center&#8221; &nbsp;], &nbsp;&#8220;window&#8221;:{ &nbsp;&nbsp;&#8220;backgroundTextStyle&#8221;:&#8221;&#8221;, &nbsp;&nbsp;&#8220;navigationBarBackgroundColor&#8221;:&nbsp;&#8220;red&#8221;, &nbsp;&nbsp;&#8220;navigationBarTitleText&#8221;:&nbsp;&#8220;\u4e00\u4e2a\u6807\u9898\u800c\u5df2&#8221;, &nbsp;&nbsp;&#8220;navigationBarTextStyle&#8221;:&#8221;white&#8221; &nbsp;}, &nbsp;&#8220;tabBar&#8221;:&nbsp;{ &nbsp;&nbsp;&#8220;list&#8221;:&nbsp;[{ &nbsp;&nbsp;&nbsp;&#8220;pagePath&#8221;:&nbsp;&#8220;pages\/index\/index&#8221;, &nbsp;&nbsp;&nbsp;&#8220;text&#8221;:&nbsp;&#8220;\u9996\u9875&#8221;, &nbsp;&nbsp;&nbsp;&#8220;iconPath&#8221;:&nbsp;&#8220;\/images\/public\/menu-cd.png&#8221;, &nbsp;&nbsp;&nbsp;&#8220;selectedIconPath&#8221;:&nbsp;&#8220;\/images\/public\/menu.png&#8221; &nbsp;&nbsp;},{ &nbsp;&nbsp;&nbsp;&#8220;pagePath&#8221;:&nbsp;&#8220;pages\/tucao\/tucao&#8221;, &nbsp;&nbsp;&nbsp;&#8220;text&#8221;:&nbsp;&#8220;\u5410\u69fd&#8221;, &nbsp;&nbsp;&nbsp;&#8220;iconPath&#8221;:&nbsp;&#8220;\/images\/public\/hot-cd.png&#8221;, &nbsp;&nbsp;&nbsp;&#8220;selectedIconPath&#8221;:&nbsp;&#8220;\/images\/public\/hot.png&#8221; &nbsp;&nbsp;},{ &nbsp;&nbsp;&nbsp;&#8220;pagePath&#8221;:&nbsp;&#8220;pages\/center\/center&#8221;, &nbsp;&nbsp;&nbsp;&#8220;text&#8221;:&nbsp;&#8220;\u6211\u7684&#8221;, &nbsp;&nbsp;&nbsp;&#8220;iconPath&#8221;:&nbsp;&#8220;\/images\/public\/center-cd.png&#8221;, &nbsp;&nbsp;&nbsp;&#8220;selectedIconPath&#8221;:&nbsp;&#8220;\/images\/public\/center.png&#8221; &nbsp;&nbsp;}], &nbsp;&nbsp;&#8220;borderStyle&#8221;:&nbsp;&#8220;white&#8221; &nbsp;} } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\u6211\u662f\u901a\u8fc7 \u5fae\u4fe1\u5c0f\u7a0b\u5e8fwx.request\u5b9e\u73b0ajax\u8bf7\u6c42\u670d\u52a1\u5668\u6570\u636e\u7684\uff0c\u4e00\u4e2a\u7a0b\u5e8f\u91cc\u9762\u6700\u591a\u80fd\u6709\u4e94\u4e2a\u8fd9\u6837\u7684\u8bf7\u6c42\u3002\u4e0b\u9762\u662findex.js\u7684\u4ee3\u7801 \/\/index.js \/\/\u83b7\u53d6\u5e94\u7528\u5b9e\u4f8b var&nbsp;app&nbsp;=&nbsp;getApp() Page({ &nbsp;data:&nbsp;{ &nbsp;&nbsp;motto:&nbsp;&#8216;Hello&nbsp;World&#8217;, &nbsp;&nbsp;userInfo:&nbsp;{}, &nbsp;&nbsp;Industry:{} &nbsp;}, &nbsp;onLoad:&nbsp;function&nbsp;(res)&nbsp;{ &nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this &nbsp;&nbsp;\/\/\u8c03\u7528\u5e94\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u83b7\u53d6\u5168\u5c40\u6570\u636e &nbsp;&nbsp;app.getUserInfo(function(userInfo){ &nbsp;&nbsp;&nbsp;\/\/\u66f4\u65b0\u6570\u636e &nbsp;&nbsp;&nbsp;that.setData({ &nbsp;&nbsp;&nbsp;&nbsp;userInfo:userInfo &nbsp;&nbsp;&nbsp;}) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-31099","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31099"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31099\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}