{"id":170925,"date":"2024-05-08T17:18:13","date_gmt":"2024-05-08T09:18:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/170925.html"},"modified":"2024-05-08T17:18:17","modified_gmt":"2024-05-08T09:18:17","slug":"javascript-post%e4%bc%a0%e5%8f%82%e6%95%b0%e8%b7%b3%e8%bd%ac%e7%ac%ac%e4%b8%89%e6%96%b9%e8%a2%ab%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8b%a6%e6%88%aa%ef%bc%8c%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%91%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/170925.html","title":{"rendered":"javascript post\u4f20\u53c2\u6570\u8df3\u8f6c\u7b2c\u4e09\u65b9\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u5982\u4f55\u907f\u514d\u5462"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27041839\/9463e432-9c46-479e-ab7a-4ee313fc48c1.webp\" alt=\"javascript post\u4f20\u53c2\u6570\u8df3\u8f6c\u7b2c\u4e09\u65b9\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u5982\u4f55\u907f\u514d\u5462\" \/><\/p>\n<p><p>\u8981\u907f\u514d\u5728\u4f7f\u7528JavaScript\u8fdb\u884cPOST\u8bf7\u6c42\u8df3\u8f6c\u5230\u7b2c\u4e09\u65b9\u65f6\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u53ef\u4ee5\u91c7\u53d6\u51e0\u79cd\u7b56\u7565\uff1a<strong>\u4f7f\u7528\u8868\u5355\u63d0\u4ea4\u3001\u901a\u8fc7\u670d\u52a1\u5668\u7aef\u4e2d\u8f6c\u3001\u4ee5\u5f39\u7a97\u6216\u65b0\u6807\u7b7e\u9875\u65b9\u5f0f\u6253\u5f00<\/strong>\u3002<strong>\u4f7f\u7528\u8868\u5355\u63d0\u4ea4<\/strong>\u662f\u6700\u5e38\u89c1\u7684\u89e3\u51b3\u65b9\u5f0f\uff0c\u5b83\u901a\u8fc7\u521b\u5efa\u52a8\u6001\u8868\u5355\u5e76\u6a21\u62df\u8868\u5355\u63d0\u4ea4\u6765\u5b9e\u73b0\uff0c\u7531\u4e8e\u8fd9\u79cd\u65b9\u5f0f\u7c7b\u4f3c\u7528\u6237\u6b63\u5e38\u7684\u70b9\u51fb\u64cd\u4f5c\uff0c\u56e0\u6b64\u4e0d\u4f1a\u88ab\u6d4f\u89c8\u5668\u5f53\u4f5c\u975e\u7528\u6237\u884c\u4e3a\u800c\u88ab\u62e6\u622a\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u8868\u5355\u63d0\u4ea4<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u52a8\u6001\u7684\u8868\u5355\uff0c\u5e76\u8bbe\u7f6e\u5176<code>action<\/code>\u5c5e\u6027\u4e3a\u76ee\u6807URL\uff0c<code>method<\/code>\u5c5e\u6027\u4e3a<code>POST<\/code>\uff0c\u518d\u901a\u8fc7JavaScript\u52a8\u6001\u6dfb\u52a0\u8868\u5355\u9879\uff0c\u6700\u540e\u63d0\u4ea4\u8868\u5355\u3002\u8fd9\u79cd\u65b9\u5f0f\u6a21\u4eff\u4e86\u7528\u6237\u5bf9\u8868\u5355\u7684\u6b63\u5e38\u63d0\u4ea4\uff0c\u56e0\u800c\u4e00\u822c\u4e0d\u4f1a\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u901a\u8fc7JavaScript\u521b\u5efa\u4e00\u4e2a\u8868\u5355\u5143\u7d20\uff0c\u5e76\u8bbe\u7f6e\u5176\u63d0\u4ea4\u7684\u76ee\u7684\u5730\uff08action\uff09\u4ee5\u53ca\u65b9\u6cd5\uff08method\uff09\u4e3aPOST\u3002\u7136\u540e\uff0c\u6839\u636e\u9700\u8981\u4f20\u9012\u7684\u6570\u636e\u52a8\u6001\u521b\u5efainput\u5143\u7d20\uff0c\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230\u8868\u5355\u4e2d\u3002\u6bcf\u4e2ainput\u5143\u7d20\u7684name\u548cvalue\u6839\u636e\u4f20\u9012\u7684\u53c2\u6570\u8bbe\u5b9a\u3002\u6700\u540e\uff0c\u901a\u8fc7\u811a\u672c\u5c06\u8868\u5355\u6dfb\u52a0\u5230\u6587\u6863\u4e2d\uff0c\u5e76\u6267\u884csubmit\u65b9\u6cd5\u63d0\u4ea4\u8868\u5355\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u5e76\u63d0\u4ea4\u4e00\u4e2a\u52a8\u6001\u8868\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u8868\u5355<\/p>\n<p>var form = document.createElement(&quot;form&quot;);<\/p>\n<p>form.setAttribute(&quot;method&quot;, &quot;post&quot;);<\/p>\n<p>form.setAttribute(&quot;action&quot;, &quot;https:\/\/third-party-url.com&quot;);<\/p>\n<p>\/\/ \u521b\u5efa\u5e76\u6dfb\u52a0\u8868\u5355\u5b57\u6bb5<\/p>\n<p>var hiddenField = document.createElement(&quot;input&quot;);<\/p>\n<p>hiddenField.setAttribute(&quot;type&quot;, &quot;hidden&quot;);<\/p>\n<p>hiddenField.setAttribute(&quot;name&quot;, &quot;parameterName&quot;);<\/p>\n<p>hiddenField.setAttribute(&quot;value&quot;, &quot;value&quot;);<\/p>\n<p>form.appendChild(hiddenField);<\/p>\n<p>\/\/ \u5c06\u8868\u5355\u6dfb\u52a0\u5230 body \u4e2d<\/p>\n<p>document.body.appendChild(form);<\/p>\n<p>\/\/ \u63d0\u4ea4\u8868\u5355<\/p>\n<p>form.submit();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u901a\u8fc7\u670d\u52a1\u5668\u7aef\u4e2d\u8f6c<\/h3>\n<\/p>\n<p><p>\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5\u662f\u901a\u8fc7\u670d\u52a1\u5668\u7aef\u7684\u4e2d\u8f6c\u3002\u8fd9\u79cd\u65b9\u5f0f\u6d89\u53ca\u5c06POST\u8bf7\u6c42\u53d1\u9001\u5230\u4f60\u63a7\u5236\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u7136\u540e\u7531\u670d\u52a1\u5668\u5b8c\u6210\u8bf7\u6c42\u5230\u7b2c\u4e09\u65b9\u7684\u8f6c\u53d1\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u907f\u514d\u76f4\u63a5\u4ece\u5ba2\u6237\u7aef\u5230\u7b2c\u4e09\u65b9\u670d\u52a1\u7684\u8de8\u57df\u8bf7\u6c42\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u964d\u4f4e\u4e86\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\u7684\u98ce\u9669\u3002<\/p>\n<\/p>\n<p><p>\u5728\u670d\u52a1\u5668\u7aef\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u63a5\u6536\u524d\u7aefPOST\u8bf7\u6c42\u7684\u63a5\u53e3\uff0c\u8be5\u63a5\u53e3\u63a5\u6536\u5230\u8bf7\u6c42\u540e\uff0c\u518d\u5229\u7528\u670d\u52a1\u5668\u7aef\u7684\u7f51\u7edc\u5e93\u5411\u7b2c\u4e09\u65b9\u670d\u52a1\u5668\u53d1\u9001POST\u8bf7\u6c42\uff0c\u83b7\u53d6\u54cd\u5e94\u540e\u518d\u5c06\u8fd9\u4e2a\u54cd\u5e94\u8fd4\u56de\u7ed9\u524d\u7aef\u3002\u4f8b\u5982\uff0c\u5728Node.js\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>axios<\/code>\u6216<code>request<\/code>\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4ee5\u5f39\u7a97\u6216\u65b0\u6807\u7b7e\u9875\u65b9\u5f0f\u6253\u5f00<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0a\u8ff0\u65b9\u6cd5\u4e0d\u9002\u7528\uff0c\u53e6\u4e00\u4e2a\u8f83\u4e3a\u7b80\u5355\u7684\u529e\u6cd5\u662f\u901a\u8fc7\u5728\u65b0\u6807\u7b7e\u9875\u6216\u5f39\u7a97\u4e2d\u6253\u5f00URL\u7684\u65b9\u5f0f\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u4e0d\u9002\u7528\u4e8e\u6240\u6709\u573a\u666f\uff0c\u4f46\u5b83\u53ef\u4ee5\u6709\u6548\u907f\u514d\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\u7684\u95ee\u9898\uff0c\u7279\u522b\u662f\u5f53\u8df3\u8f6c\u5bf9\u7528\u6237\u4f53\u9a8c\u5f71\u54cd\u4e0d\u5927\u65f6\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>window.open<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5728\u65b0\u6807\u7b7e\u9875\u6216\u65b0\u7a97\u53e3\u4e2d\u6253\u5f00\u6307\u5b9a\u7684URL\u3002\u4e3a\u4e86\u907f\u514d\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u6700\u597d\u5728\u7528\u6237\u89e6\u53d1\u7684\u4e8b\u4ef6\u4e2d\u8c03\u7528<code>window.open<\/code>\uff0c\u5982\u70b9\u51fb\u4e8b\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">button.addEventListener(&#039;click&#039;, function() {<\/p>\n<p>    window.open(&#039;https:\/\/third-party-url.com&#039;, &#039;_blank&#039;);<\/p>\n<p>});<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884cJavaScript POST\u8bf7\u6c42\u65f6\uff0c\u906d\u9047\u6d4f\u89c8\u5668\u62e6\u622a\u662f\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u3002\u901a\u8fc7\u4f7f\u7528\u8868\u5355\u63d0\u4ea4\u3001\u670d\u52a1\u5668\u7aef\u4e2d\u8f6c\u3001\u6216\u4ee5\u5f39\u7a97\u548c\u65b0\u6807\u7b7e\u9875\u65b9\u5f0f\u6253\u5f00\u7b49\u7b56\u7565\uff0c\u53ef\u4ee5\u6709\u6548\u89c4\u907f\u8fd9\u4e00\u95ee\u9898\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\uff0c\u56e0\u6b64\u5728\u9009\u62e9\u89e3\u51b3\u65b9\u6848\u65f6\uff0c\u5e94\u8003\u8651\u5230\u5b9e\u9645\u7684\u9700\u6c42\u548c\u7528\u6237\u4f53\u9a8c\u3002\u901a\u8fc7\u5b9e\u8df5\u548c\u6d4b\u8bd5\uff0c\u627e\u5230\u6700\u9002\u5408\u4f60\u9879\u76ee\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u4e3a\u4ec0\u4e48\u6d4f\u89c8\u5668\u4f1a\u62e6\u622a\u7b2c\u4e09\u65b9\u8df3\u8f6c\uff1f<\/strong><\/p>\n<p>\u6d4f\u89c8\u5668\u4e4b\u6240\u4ee5\u4f1a\u62e6\u622a\u7b2c\u4e09\u65b9\u8df3\u8f6c\uff0c\u662f\u56e0\u4e3a\u8fd9\u79cd\u8df3\u8f6c\u884c\u4e3a\u6709\u6f5c\u5728\u7684\u5b89\u5168\u98ce\u9669\u3002\u4e3a\u4e86\u4fdd\u62a4\u7528\u6237\u7684\u5b89\u5168\u548c\u9690\u79c1\uff0c\u6d4f\u89c8\u5668\u901a\u5e38\u4f1a\u9ed8\u8ba4\u7981\u6b62\u6216\u62e6\u622a\u643a\u5e26\u53c2\u6570\u7684\u7b2c\u4e09\u65b9\u8df3\u8f6c\u3002<\/p>\n<p><strong>Q2: \u5982\u4f55\u907f\u514d\u6d4f\u89c8\u5668\u62e6\u622a\u7b2c\u4e09\u65b9\u8df3\u8f6c\uff1f<\/strong><\/p>\n<p>\u8981\u907f\u514d\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u4ee3\u66ff\u7edd\u5bf9\u8def\u5f84<\/strong>\uff1a\u5c3d\u91cf\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u8df3\u8f6c\uff0c\u5728\u94fe\u63a5\u4e2d\u4e0d\u5305\u542b\u5177\u4f53\u7684\u57df\u540d\u4fe1\u606f\u3002\u8fd9\u6837\u6d4f\u89c8\u5668\u4f1a\u5c06\u8df3\u8f6c\u89c6\u4e3a\u540c\u4e00\u7ad9\u70b9\u7684\u64cd\u4f5c\uff0c\u51cf\u5c11\u88ab\u62e6\u622a\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5c1d\u8bd5\u4f7f\u7528\u9875\u9762\u91cd\u5b9a\u5411<\/strong>\uff1a\u901a\u8fc7\u5728\u9875\u9762\u4e2d\u6dfb\u52a0\u4e00\u6bb5JavaScript\u4ee3\u7801\uff0c\u4f7f\u7528\u9875\u9762\u91cd\u5b9a\u5411\u5b9e\u73b0\u8df3\u8f6c\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528<code>window.location.href<\/code>\u6216<code>form<\/code>\u7684post\u65b9\u5f0f\u8fdb\u884c\u8df3\u8f6c\u3002\u9875\u9762\u91cd\u5b9a\u5411\u53ef\u4ee5\u7ed5\u8fc7\u4e00\u4e9b\u6d4f\u89c8\u5668\u7684\u62e6\u622a\u673a\u5236\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5408\u6cd5\u7684HTTPS\u8bc1\u4e66<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u7f51\u7ad9\u4f7f\u7528\u4e86HTTPS\u534f\u8bae\uff0c\u786e\u4fdd\u4f60\u7684\u7f51\u7ad9\u4f7f\u7528\u4e86\u5408\u6cd5\u7684SSL\u8bc1\u4e66\u3002\u6d4f\u89c8\u5668\u7ecf\u5e38\u4f1a\u62e6\u622a\u4f7f\u7528\u65e0\u6548\u3001\u8fc7\u671f\u6216\u8005\u672a\u7ecf\u9a8c\u8bc1\u7684\u8bc1\u4e66\u7684\u7b2c\u4e09\u65b9\u8df3\u8f6c\u3002<\/p>\n<\/li>\n<\/ol>\n<p><strong>Q3: \u8fd8\u6709\u5176\u4ed6\u7684\u65b9\u6cd5\u53ef\u4ee5\u907f\u514d\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\u5417\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u6dfb\u52a0\u4ea4\u4e92\u64cd\u4f5c<\/strong>\uff1a\u5728\u8df3\u8f6c\u4e4b\u524d\uff0c\u5f15\u5bfc\u7528\u6237\u8fdb\u884c\u4e00\u4e9b\u70b9\u51fb\u6216\u8005\u5176\u4ed6\u7684\u4ea4\u4e92\u64cd\u4f5c\uff0c\u8fd9\u6837\u6d4f\u89c8\u5668\u4f1a\u5c06\u8df3\u8f6c\u89c6\u4e3a\u7528\u6237\u4e3b\u52a8\u884c\u4e3a\uff0c\u800c\u4e0d\u662f\u81ea\u52a8\u8df3\u8f6c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u8fc7\u591a\u7684\u8df3\u8f6c<\/strong>\uff1a\u5c3d\u91cf\u51cf\u5c11\u4ece\u4e00\u4e2a\u9875\u9762\u8df3\u8f6c\u5230\u53e6\u4e00\u4e2a\u9875\u9762\u7684\u6b21\u6570\uff0c\u8fc7\u591a\u7684\u8df3\u8f6c\u5bb9\u6613\u88ab\u6d4f\u89c8\u5668\u89c6\u4e3a\u6076\u610f\u884c\u4e3a\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u65b0\u6d4f\u89c8\u5668\u7248\u672c<\/strong>\uff1a\u786e\u4fdd\u4f7f\u7528\u7684\u6d4f\u89c8\u5668\u662f\u6700\u65b0\u7248\u672c\uff0c\u56e0\u4e3a\u6d4f\u89c8\u5668\u901a\u5e38\u4f1a\u901a\u8fc7\u66f4\u65b0\u6765\u4fee\u590d\u5df2\u77e5\u7684\u5b89\u5168\u6f0f\u6d1e\u548c\u98ce\u9669\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u8981\u907f\u514d\u5728\u4f7f\u7528JavaScript\u8fdb\u884cPOST\u8bf7\u6c42\u8df3\u8f6c\u5230\u7b2c\u4e09\u65b9\u65f6\u88ab\u6d4f\u89c8\u5668\u62e6\u622a\uff0c\u53ef\u4ee5\u91c7\u53d6\u51e0\u79cd\u7b56\u7565\uff1a\u4f7f\u7528\u8868\u5355\u63d0\u4ea4\u3001\u901a [&hellip;]","protected":false},"author":3,"featured_media":170929,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/170925"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=170925"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/170925\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/170929"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=170925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=170925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=170925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}