{"id":199063,"date":"2025-05-03T12:25:57","date_gmt":"2025-05-03T04:25:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199063\/"},"modified":"2025-05-03T12:25:57","modified_gmt":"2025-05-03T04:25:57","slug":"%e7%94%a8jquery%e7%9a%84getjson%e5%ae%9e%e7%8e%b0ecshop%e4%b8%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e8%b7%a8%e5%9f%9f%e8%af%bb%e5%8f%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199063\/","title":{"rendered":"\u7528Jquery\u7684getJSON\u5b9e\u73b0ecshop\u4e24\u7f51\u7ad9\u4e4b\u95f4\u8de8\u57df\u8bfb\u53d6"},"content":{"rendered":"<p>&nbsp;<span style=\"font-family: \u5b8b\u4f53, Verdana, Arial;line-height: 18px;font-size: 12px\">\u8fd9\u4e2a\u95ee\u9898\u8ddfECSHOP\u7684\u5173\u7cfb\u4e0d\u662f\u5f88\u76f4\u63a5\uff0c\u4e00\u822c\u7528\u6237\u7528\u4e0d\u5230\u3002 <\/span><\/p>\n<p style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\"> \u53ea\u662f\u5bf9\u4e8e\u9ad8\u7ea7\u7528\u6237\u53ef\u80fd\u4f1a\u6709\u70b9\u5e2e\u52a9\uff0c\u4e3e\u4f8b\u8bf4\u660e\uff1a<\/p>\n<p> \u6bd4\u65b9\u4e24\u4e2aECSHOP\u7f51\u7ad9\u62e5\u6709\u4e0d\u540c\u57df\u540d\uff0c\u4f4d\u4e8e\u4e0d\u540c\u670d\u52a1\u5668\u4e0a\uff0c\u53cc\u65b9\u4e4b\u95f4\u53c8\u4e0d\u80fd\u76f4\u8fde\u6570\u636e\u5e93\u7684\u524d\u63d0\u4e0b\uff0c\u4e24\u4e2a\u7f51\u7ad9\u4e4b\u95f4\u5982\u679c\u60f3\u5171\u4eab\u8ba2\u5355\u6570\u636e\u3002<br \/> \u90a3\u4e48\u4e5f\u8bb8\u53ef\u4ee5\u4f7f\u7528 $.getJSON \u6765\u89e3\u51b3\u3002<\/p>\n<p> test.php,\u5728 www.eshop.com&nbsp; \u6839\u76ee\u5f55\u4e2d<br \/> test.php\u4ee3\u7801\uff1a&nbsp;<br \/> <strong>PHP\u4ee3\u7801<br \/> <\/strong><\/p>\n<table cellspacing=\"0\" cellpadding=\"5\" style=\"border-right-width: 1px;border-right-style: solid;border-top-width: 1px;border-top-style: solid;background-image: initial;background-attachment: initial;border-left-width: 1px;border-left-style: solid;width: 673px;border-bottom-width: 1px;border-bottom-style: solid;background-position: initial initial;background-repeat: initial initial\">\n<tbody>\n<tr>\n<td><font style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">&lt;?php&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; $dal=$_GET[&#8216;callback&#8217;];&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; $arr=array(&#8220;name&#8221;=&gt;&#8221;4nail&#8221;, &#8220;age&#8221;=&gt;20);&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; $jarr=json_encode($arr);&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; echo $dal.'(&#8216;.$jarr,&#8217;)&#8217;;&nbsp;&nbsp;&nbsp;<br \/> ?&gt;<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">&nbsp;<\/p>\n<p> test.html\u5728 www.ldhost.cn&nbsp;\u6839\u76ee\u5f55\u4e0b <\/p>\n<p style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">test.html\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>    Html\u4ee3\u7801&nbsp;  <\/p>\n<table cellspacing=\"0\" cellpadding=\"5\" style=\"border-right-width: 1px;border-right-style: solid;border-top-width: 1px;border-top-style: solid;background-image: initial;background-attachment: initial;border-left-width: 1px;border-left-style: solid;width: 673px;border-bottom-width: 1px;border-bottom-style: solid;background-position: initial initial;background-repeat: initial initial\">\n<tbody>\n<tr>\n<td><font style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;head&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=gb2312&#8243; \/&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;title&gt;\u65e0\u6807\u9898\u6587\u6863&lt;\/title&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;script language=&#8221;javascript&#8221; type=&#8221;text\/javascript&#8221; src=&#8221;Scripts\/jquery.min.js&#8221;&gt;&lt;\/script&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;script type=&#8221;text\/javascript&#8221;&gt;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; $(function(){&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&#8220;#test&#8221;).click(function(){&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.getJSON(&#8220;http:\/\/www.ecshop.com\/test.php?callback=?&#8221;,function(data){&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(data.name);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;<br \/> &lt;\/script&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;\/head&gt;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;&nbsp;<br \/> &lt;body&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;div style=&#8221;width:100px;height:100px;background-color:#F00&#8243; id=&#8221;test&#8221;&gt;\u70b9\u51fb\u8de8\u57df\u52a0\u8f7d&lt;\/div&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;\/body&gt;&nbsp;&nbsp;&nbsp;<br \/> &lt;\/html&gt;<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> \u5173\u952e\u7684\u4e00\u70b9\u5728\u4e8e \u5728$.getJSON()\u4e2d\u7684url\u53c2\u6570\u672b\u5c3e\u8981\u52a0\u4e2acallback=?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n<br \/> \u4e0d\u4e00\u5b9a\u975e\u53eb callback\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5176\u4ed6\u7684\u540d\u79f0\uff0c\u5728test.php\u6587\u4ef6\u4e2d\uff0c\u6539\u76f8\u5e94\u7684\u540d\u79f0\uff0c\u5c31ok\u5566\uff01<br \/>\n<br \/> \u5728\u8f93\u51fa json \u6570\u636e\u65f6\uff0c\u5fc5\u987b\u8981\u52a0\u4e0a $_GET[&#8216;callback&#8217;] \u548c\u4e24\u4e2a\u62ec\u53f7\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837&nbsp;<br \/>\n<br \/> <br \/>\n<strong><span style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">echo $dal.'(&#8216;.$jarr,&#8217;)&#8217;;<span style=\"border-top-style: none;border-right-style: none;border-bottom-style: none;border-left-style: none;border-width: initial;border-color: initial;list-style-type: none;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px\">z<\/span><\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u8fd9\u4e2a\u95ee\u9898\u8ddfECSHO&#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-199063","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199063","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=199063"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199063\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}