{"id":199189,"date":"2025-05-03T14:01:42","date_gmt":"2025-05-03T06:01:42","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199189\/"},"modified":"2025-05-03T14:01:42","modified_gmt":"2025-05-03T06:01:42","slug":"ecshop%e5%90%8e%e5%8f%b0%e9%80%9a%e8%bf%87ajax%e6%90%9c%e7%b4%a2%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199189\/","title":{"rendered":"ecshop\u540e\u53f0\u901a\u8fc7ajax\u641c\u7d22\u539f\u7406"},"content":{"rendered":"<p><span style=\"font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">ecshop\u7684\u641c\u7d22\u5176\u5b9e\u662f\u529f\u80fd\u5341\u5206\u5f3a\u5927\u7684\uff0c\u4f46\u662fecshop\u641c\u7d22\u529f\u80fd\u524d\u53f0\u548c\u540e\u53f0\u8fd8\u4e0d\u5927\u4e00\u6837,\u524d\u53f0\u4e3b\u8981\u662f\u901a\u8fc7get\u65b9\u5f0f,\u63d0\u4ea4\u7684url\u8fdb\u884c\u5206\u9875,\u800c\u5728ecshop\u7684\u540e\u53f0,\u5219\u662f\u63a5\u53d7\u8868\u5355\u7684\u641c\u7d22\u6761\u4ef6,\u7136\u540e\u901a\u8fc7js\u53d1\u5e03\u5230ajax.\u6700\u540e\u53c8\u901a\u8fc7ecshop\u7684ajax\u5c06\u7ed3\u679c\u8fd4\u56de.\u7136\u540e\u5728\u663e\u793a\u6700\u540e\u7684\u641c\u7d22\u7ed3\u679c.<\/span><\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; \u6211\u4eec\u6765\u4e3e\u4e2a\u4f8b\u5b50,\u5177\u4f53\u5206\u6790\u4e0becshop\u540e\u53f0\u901a\u8fc7ajax\u65b9\u5f0f\u6765\u8fdb\u884c\u641c\u7d22.<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; \u6bd4\u5982\u6211\u4eec\u901a\u8fc7ecshop\u540e\u53f0\u7684ajax\u65b9\u5f0f\u6765\u641c\u7d22\u9000\u6362\u8d27\u8ba2\u5355<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; 1:\u5fc5\u987b\u5728htm\u4e2d\u589e\u589e\u52a0\u4ee5\u4e0b\u641c\u7d22\u6846,\u8ba2\u5355\u53f7 &lt;input type=&#8221;text&#8221; name=&#8221;order_sn&#8221; size=&#8221;15&#8243; \/&gt;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;2:html\u4e2d\u7684ajax\u53ef\u4ee5\u5199\u6210\u4ee5\u4e0b\u683c\u5f0f<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; listTable.filter[&#8216;order_sn&#8217;] = Utils.trim(document.forms[&#8216;searchForm&#8217;].elements[&#8216;order_sn&#8217;].value);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listTable.filter[&#8216;page&#8217;] = 1;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listTable.loadList();<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp; \u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b,\u5c31\u662f\u901a\u8fc7listTable.loadList();\u6765\u89e6\u53d1ajax\u7684\u3002<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;3:\u6211\u4eec\u518d\u770bphp\u8c03\u7528\u3002<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp; $result = get_filter();<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp; if ($result === false)<br \/> &nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u5982\u679c\u8fd4\u56de\u7ed3\u679c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u5c31\u8fdb\u884cajax\u7ed3\u679c\u7b5b\u9009<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;invoice_no&#8217;]&nbsp;&nbsp; = empty($_REQUEST[&#8216;invoice_no&#8217;]) ? &#8221; : trim($_REQUEST[&#8216;invoice_no&#8217;]);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($_REQUEST[&#8216;is_ajax&#8217;] == 1)<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;order_sn&#8217;] = json_str_iconv($filter[&#8216;order_sn&#8217;]);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;sort_by&#8217;]&nbsp;&nbsp;&nbsp; = empty($_REQUEST[&#8216;sort_by&#8217;]) ? &#8216;cid&#8217; : trim($_REQUEST[&#8216;sort_by&#8217;]);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;sort_order&#8217;] = empty($_REQUEST[&#8216;sort_order&#8217;]) ? &#8216;DESC&#8217; : trim($_REQUEST[&#8216;sort_order&#8217;]);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; $sql = &#8220;SELECT COUNT(*) FROM &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;change&#8217;) .<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8221; WHERE 1 &#8221; . $where;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;record_count&#8217;] = $GLOBALS[&#8216;db&#8217;]-&gt;getOne($sql);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter = page_and_size($filter);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/* \u83b7\u6d3b\u52a8\u6570\u636e *\/<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sql = &#8220;SELECT * &#8220;.<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8221; FROM &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;change&#8217;) .<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8221; WHERE 1 &#8221; . $where .<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8221; ORDER by $filter[sort_by] $filter[sort_order] LIMIT &#8220;. $filter[&#8216;start&#8217;] .&#8221;, &#8221; . $filter[&#8216;page_size&#8217;];<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter[&#8216;keywords&#8217;] = stripslashes($filter[&#8216;keywords&#8217;]);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set_filter($filter, $sql);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; }else{<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $sql&nbsp;&nbsp;&nbsp; = $result[&#8216;sql&#8217;];<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filter = $result[&#8216;filter&#8217;];<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">}<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp; 4:\u6700\u540e\u5c06\u67e5\u8be2\u7ed3\u679c\u8fd4\u56de<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; $arr = array(&#8216;res&#8217; =&gt; $row, &#8216;filter&#8217; =&gt; $filter, &#8216;page_count&#8217; =&gt; $filter[&#8216;page_count&#8217;], &#8216;record_count&#8217; =&gt; $filter[&#8216;record_count&#8217;]);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp;&nbsp; return $arr;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; \u6211\u4eec\u5728\u6765\u5206\u6790\u4e0b,res\u662f\u8fd4\u56de\u7684\u6240\u6709\u6570\u636e,filter\u662f\u8fc7\u6ee4\u68c0\u7d22\u6761\u4ef6,page_count\u662f\u5206\u9875\u6570\u91cf,record_count\u8868\u793a\u67e5\u8be2\u7684\u8bb0\u5f55\u603b\u6570.<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;font-family: Verdana, Arial, Tahoma;font-size: 14px;line-height: 25px\">&nbsp;&nbsp; \u901a\u8fc7\u4ee5\u4e0a\u5c01\u88c5,\u6211\u4eec\u53ef\u4ee5\u987a\u5229\u7684\u5728ecshop\u540e\u53f0\u4f7f\u7528ajax\u68c0\u7d22\u6570\u636e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ecshop\u7684\u641c\u7d22\u5176\u5b9e\u662f\u529f\u80fd\u5341\u5206&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199189","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199189"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199189\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}