{"id":60458,"date":"2025-04-24T08:19:48","date_gmt":"2025-04-24T00:19:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60458\/"},"modified":"2025-04-24T08:19:48","modified_gmt":"2025-04-24T00:19:48","slug":"ecshop-ajax%e5%92%8csmarty-fetch%e7%9a%84%e7%bb%93%e5%90%88-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60458\/","title":{"rendered":"ecshop Ajax\u548cSmarty fetch\u7684\u7ed3\u5408"},"content":{"rendered":"<p> ecshop\u7684ajax\u65e0\u5237\u65b0\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u6280\u672f\u5341\u5206\u6d41\u884c\uff0c\u4f46\u662f\u6211\u4e4b\u524d\u7684\u505a\u6cd5\u662f\u83b7\u53d6\u4e00\u5806json\u7684\u6570\u503c.\u7136\u540e\u5728\u524d\u7aef\u9875\u9762\u7531javascript\u6765\u89e3\u6790\u66ff\u6362html.\u8fd9\u6837\u64cd\u4f5c\u6bd4\u8f83\u7e41\u7410\u3002<br \/> \u3000\u3000\u5728\u5f00\u53d1ecshop\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53d1\u73b0ecshop\u7684\u65e0\u5237\u65b0\u52a0\u8f7d\uff0c\u5bf9\u4e8e\u8fd4\u56de\u6765\u7684json\u503c\u6ca1\u6709\u4f5c\u89e3\u6790\u3002\u800c\u662f\u76f4\u63a5\u7528innerHTML\u66ff\u6362<\/p>\n<blockquote>\n<p> \/admin\/js\/listtable.js<\/p>\n<\/blockquote>\n<p> document.getElementById(&#8216;listDiv&#8217;).innerHTML = result.content;<\/p>\n<p> \u3000\u3000\u8fd9\u662f\u7531\u4e8e\u5728\u670d\u52a1\u7aef\uff0c\u5373php\u6587\u4ef6\u91cc\u5df2\u7ecf\u628a\u6570\u636e\u7ec4\u5408\u6210\u53ef\u4ee5\u76f4\u63a5\u663e\u793a\u7684html\u4e86\u3002<br \/> \u8fd9\u4e2a\u662f\u7528smarty-&gt;fetch\u51fd\u6570\u5b9e\u73b0\u3002fetch\u51fd\u6570\u548cdisplay\u4e0d\u540c\u4e4b\u5904\uff0cfetch\u53ea\u8d4b\u503c,\u4e0d\u663e\u793a\u3002<\/p>\n<pre>\r\n    $order_list = order_list();\r\n\r\n    $smarty-&gt;assign('order_list',   $order_list['orders']);\r\n    $smarty-&gt;assign('filter',       $order_list['filter']);\r\n    $smarty-&gt;assign('record_count', $order_list['record_count']);\r\n    $smarty-&gt;assign('page_count',   $order_list['page_count']);\r\n    $sort_flag  = sort_flag($order_list['filter']);\r\n    $smarty-&gt;assign($sort_flag['tag'], $sort_flag['img']);\r\n\r\n\r\n    make_json_result($smarty-&gt;fetch('order_list.htm'), '', array('filter' =&gt;       $order_list['filter'], 'page_count' =&gt; $order_list['page_count']));<\/pre>\n<p> \u8fd9\u6837ajax\u524d\u7aef\u83b7\u53d6\u7684result.content\u5c31\u662f\u4e00\u7ec4html\u5185\u5bb9\u4e86\u3002\u4e0d\u7528\u518d\u7528js\u64cd\u4f5c\u66ff\u6362html<\/p>\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>ecshop\u7684ajax\u65e0\u5237\u65b0\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u6280\u672f\u5341\u5206\u6d41\u884c\uff0c\u4f46\u662f\u6211\u4e4b\u524d\u7684\u505a\u6cd5\u662f\u83b7\u53d6\u4e00\u5806json\u7684\u6570\u503c.\u7136\u540e\u5728\u524d\u7aef\u9875\u9762\u7531javascript\u6765\u89e3\u6790\u66ff\u6362html.\u8fd9\u6837\u64cd\u4f5c\u6bd4\u8f83\u7e41\u7410\u3002 \u3000\u3000\u5728\u5f00\u53d1ecshop\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53d1\u73b0ecshop\u7684\u65e0\u5237\u65b0\u52a0\u8f7d\uff0c\u5bf9\u4e8e\u8fd4\u56de\u6765\u7684json\u503c\u6ca1\u6709\u4f5c\u89e3\u6790\u3002\u800c\u662f\u76f4\u63a5\u7528innerHTML\u66ff\u6362 \/admin\/js\/listtable.js document.getElementById(&#8216;listDiv&#8217;).innerHTML = result.content; \u3000\u3000\u8fd9\u662f\u7531\u4e8e\u5728\u670d\u52a1\u7aef\uff0c\u5373php\u6587\u4ef6\u91cc\u5df2\u7ecf\u628a\u6570\u636e\u7ec4\u5408\u6210\u53ef\u4ee5\u76f4\u63a5\u663e\u793a\u7684html\u4e86\u3002 \u8fd9\u4e2a\u662f\u7528smarty-&gt;fetch\u51fd\u6570\u5b9e\u73b0\u3002fetch\u51fd\u6570\u548cdisplay\u4e0d\u540c\u4e4b\u5904\uff0cfetch\u53ea\u8d4b\u503c,\u4e0d\u663e\u793a\u3002 $order_list = order_list(); $smarty-&gt;assign(&#8216;order_list&#8217;, $order_list[&#8216;orders&#8217;]); $smarty-&gt;assign(&#8216;filter&#8217;, $order_list[&#8216;filter&#8217;]); $smarty-&gt;assign(&#8216;record_count&#8217;, $order_list[&#8216;record_count&#8217;]); $smarty-&gt;assign(&#8216;page_count&#8217;, $order_list[&#8216;page_count&#8217;]); $sort_flag = sort_flag($order_list[&#8216;filter&#8217;]); $smarty-&gt;assign($sort_flag[&#8216;tag&#8217;], $sort_flag[&#8216;img&#8217;]); make_json_result($smarty-&gt;fetch(&#8216;order_list.htm&#8217;), &#8221;, array(&#8216;filter&#8217; =&gt; $order_list[&#8216;filter&#8217;], &#8216;page_count&#8217; =&gt; $order_list[&#8216;page_count&#8217;])); \u8fd9\u6837ajax\u524d\u7aef\u83b7\u53d6\u7684result.content\u5c31\u662f\u4e00\u7ec4html\u5185\u5bb9\u4e86\u3002\u4e0d\u7528\u518d\u7528js\u64cd\u4f5c\u66ff\u6362html<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-60458","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60458","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=60458"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60458\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}