{"id":49475,"date":"2024-12-02T10:08:49","date_gmt":"2024-12-02T02:08:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49475\/"},"modified":"2024-12-02T10:08:49","modified_gmt":"2024-12-02T02:08:49","slug":"jquery-post%e5%92%8cfetch%e5%8f%91%e9%80%81post%e8%af%b7%e6%b1%82%e6%97%b6php%e6%8e%a5%e6%94%b6%e6%95%b0%e6%8d%ae%e5%b7%ae%e5%bc%82%e4%bd%95%e5%9c%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49475\/","title":{"rendered":"jQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>jQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300ajQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733127345674d6cb183b92.jpg\" class=\"aligncenter\" title=\"jQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f\u63d2\u56fe\" alt=\"jQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jquery $.post() \u4e0e fetch \u53d1\u9001\u6570\u636e\u65f6\u4e3a\u4f55\u8868\u73b0\u4e0d\u540c\uff1f<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 $_post \u8d85\u5168\u5c40\u53d8\u91cf\u5904\u7406 post \u6570\u636e\u65f6\uff0cphp \u53ea\u652f\u6301 application\/x-www-form-urlencoded \u548c multipart\/form-data \u7c7b\u578b\u7684\u8868\u5355\u6570\u636e\u3002<\/p>\n<p>\u7136\u800c\uff0cfetch \u9ed8\u8ba4\u53d1\u9001\u7684\u662f json \u6570\u636e\uff0c\u5176\u8bf7\u6c42\u5934\u4e3a application\/json\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u524d\u7aef\u4ee3\u7801\u4f7f\u7528 fetch \u53d1\u9001\u6570\u636e\uff0c\u4e5f\u65e0\u6cd5\u901a\u8fc7 $_post \u6b63\u5e38\u83b7\u53d6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>\u524d\u7aef\uff1a<\/strong><\/p>\n<ul>\n<li>\u4fee\u6539\u53d1\u9001\u6570\u636e\u7684\u8bf7\u6c42\u5934\u4e3a application\/x-www-form-urlencoded\uff0c\u540c\u65f6\u4f7f\u7528 qs \u5305\u5c06\u6570\u636e\u5e8f\u5217\u5316\u3002<\/li>\n<\/ul>\n<pre>fetch('http:\/\/localhost\/', {\n  method: 'post',\n  headers: {\n    'content-type': 'application\/x-www-form-urlencoded;charset=utf-8'\n  },\n  body: qs.stringify({\n    action: 'send_data',\n    talk_code: '11223344',\n    cid: '27',\n    token: 'crx',\n    content: '\u8fd9\u662f\u4e00\u6761\u6d4b\u8bd5\u5185\u5bb9~~',\n  })\n}).then(res =&amp;gt; res.text()).then(json =&amp;gt; console.log(json))<\/pre>\n<p><strong>\u540e\u7aef\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 php:\/\/input \u83b7\u53d6 post \u6570\u636e\u5e76\u89e3\u6790\u4e3a\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<pre>$input = json_decode(file_get_contents('php:\/\/input'), true) ?: [];\n\nif ($_SERVER['REQUEST_METHOD'] == 'POST') {\n    if (@$input['action'] == 'send_data') {}\n}<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300ajQuery $.post()\u548cfetch\u53d1\u9001POST\u8bf7\u6c42\u65f6PHP\u63a5\u6536\u6570\u636e\u5dee\u5f02\u4f55\u5728\uff1f\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 jquery $.post() \u4e0e fetch \u53d1\u9001\u6570\u636e\u65f6\u4e3a\u4f55\u8868\u73b0\u4e0d\u540c\uff1f \u5728\u4f7f\u7528 $_post \u8d85\u5168\u5c40\u53d8\u91cf\u5904\u7406 post \u6570\u636e\u65f6\uff0cphp \u53ea\u652f\u6301 application\/x-www-form-urlencoded \u548c multipart\/form-data \u7c7b\u578b\u7684\u8868\u5355\u6570\u636e\u3002 \u7136\u800c\uff0cfetch \u9ed8\u8ba4\u53d1\u9001\u7684\u662f json \u6570\u636e\uff0c\u5176\u8bf7\u6c42\u5934\u4e3a application\/json\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u524d\u7aef\u4ee3\u7801\u4f7f\u7528 fetch \u53d1\u9001\u6570\u636e\uff0c\u4e5f\u65e0\u6cd5\u901a\u8fc7 $_post \u6b63\u5e38\u83b7\u53d6\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u524d\u7aef\uff1a \u4fee\u6539\u53d1\u9001\u6570\u636e\u7684\u8bf7\u6c42\u5934\u4e3a application\/x-www-form-urlencoded\uff0c\u540c\u65f6\u4f7f\u7528 qs \u5305\u5c06\u6570\u636e\u5e8f\u5217\u5316\u3002 fetch(&#8216;http:\/\/localhost\/&#8217;, { method: &#8216;post&#8217;, headers: { &#8216;content-type&#8217;: &#8216;application\/x-www-form-urlencoded;charset=utf-8&#8217; }, body: qs.stringify({ action: &#8216;send_data&#8217;, talk_code: &#8216;11223344&#8217;, cid: &#8217;27&#8217;, token: &#8216;crx&#8217;, content: &#8216;\u8fd9\u662f\u4e00\u6761\u6d4b\u8bd5\u5185\u5bb9~~&#8217;, [&hellip;]<\/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-49475","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49475","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=49475"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49475\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}