{"id":3375,"date":"2024-11-10T15:07:46","date_gmt":"2024-11-10T07:07:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3375\/"},"modified":"2024-11-10T15:07:46","modified_gmt":"2024-11-10T07:07:46","slug":"%e5%a6%82%e4%bd%95js%e6%8f%90%e4%ba%a4%e7%99%be%e5%ba%a6%e6%94%b6%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3375\/","title":{"rendered":"\u5982\u4f55js\u63d0\u4ea4\u767e\u5ea6\u6536\u5f55"},"content":{"rendered":"<blockquote><p>\n  \u901a\u8fc7\u767e\u5ea6\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\u5f00\u653e\u63a5\u53e3\uff0c\u53ef\u76f4\u63a5\u63d0\u4ea4\u7f51\u5740\u6536\u5f55\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a\u83b7\u53d6 access token\u3002\u521b\u5efa submit_url \u8bf7\u6c42\uff0c\u6307\u5b9a url \u548c\u53c2\u6570\u3002\u53d1\u9001\u8bf7\u6c42\uff0c\u5904\u7406\u670d\u52a1\u5668\u54cd\u5e94\u3002\u89e3\u6790\u54cd\u5e94\uff0c\u83b7\u53d6\u63d0\u4ea4\u72b6\u6001\u548c\u4fe1\u606f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110811040945355.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55js\u63d0\u4ea4\u767e\u5ea6\u6536\u5f55\u63d2\u56fe\" alt=\"\u5982\u4f55js\u63d0\u4ea4\u767e\u5ea6\u6536\u5f55\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u63d0\u4ea4\u6536\u5f55<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u63d0\u4ea4\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u901a\u8fc7\u767e\u5ea6\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\u7684\u5f00\u653e\u63a5\u53e3\uff0c\u76f4\u63a5\u63d0\u4ea4\u7f51\u5740\u8fdb\u884c\u6536\u5f55\u7533\u8bf7\u3002<\/p>\n<p><strong>\u5177\u4f53\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u83b7\u53d6  token\uff1a<\/strong>\u4f7f\u7528\u767e\u5ea6\u8d26\u53f7\u767b\u5f55\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\uff0c\u83b7\u53d6 access token\u3002<\/li>\n<li> <strong>\u521b\u5efa submit_url \u8bf7\u6c42\uff1a<\/strong>\u4f7f\u7528 fetch API \u6216 XMLHttpRequest \u521b\u5efa\u4e00\u4e2a POST \u8bf7\u6c42\uff0c\u5e76\u6307\u5b9a submit_url API \u7684 URL \u548c\u53c2\u6570\u3002<\/li>\n<li> <strong>\u53d1\u9001\u8bf7\u6c42\uff1a<\/strong>\u53d1\u9001\u521b\u5efa\u597d\u7684\u8bf7\u6c42\uff0c\u5e76\u5904\u7406\u670d\u52a1\u5668\u54cd\u5e94\u3002<\/li>\n<li> <strong>\u89e3\u6790\u54cd\u5e94\uff1a<\/strong>\u89e3\u6790\u670d\u52a1\u5668\u54cd\u5e94\uff0c\u83b7\u53d6\u63d0\u4ea4\u72b6\u6001\u548c\u76f8\u5e94\u4fe1\u606f\u3002<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>async function submitUrl(url, access_token) {\n  const response = await fetch('https:\/\/www.baidu.com\/submit\/api\/urlupdate', {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application\/json'\n    },\n    body: JSON.stringify({\n      url: url,\n      access_token: access_token\n    })\n  });\n\n  const data = await response.json();\n  if (data.code === 0) {\n    console.log('\u63d0\u4ea4\u6210\u529f');\n  } else {\n    console.error('\u63d0\u4ea4\u5931\u8d25\uff1a', data.message);\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>sitemap \u63d0\u4ea4\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5c06\u5305\u542b\u7f51\u5740\u5217\u8868\u7684 sitemap \u6587\u4ef6\u4e0a\u4f20\u81f3\u767e\u5ea6\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\u3002<\/p>\n<p><strong>\u5177\u4f53\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u751f\u6210 sitemap \u6587\u4ef6\uff1a<\/strong>\u4f7f\u7528 sitemap \u751f\u6210\u5668\u751f\u6210\u5305\u542b\u9700\u8981\u6536\u5f55\u7f51\u5740\u7684 XML sitemap \u6587\u4ef6\u3002<\/li>\n<li> <strong>\u4e0a\u4f20 Sitemap \u6587\u4ef6\uff1a<\/strong>\u767b\u5f55\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\uff0c\u5728Sitemap\u7ba1\u7406\u9875\u9762\u4e0a\u4f20\u751f\u6210\u7684 sitemap \u6587\u4ef6\u3002<\/li>\n<li> <strong>\u63d0\u4ea4 Sitemap\uff1a<\/strong>\u5728\u63d0\u4ea4 Sitemap \u9875\u9762\u4e2d\uff0c\u63d0\u4ea4\u5df2\u4e0a\u4f20\u7684 Sitemap \u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u767e\u5ea6\u5b98\u65b9\u5efa\u8bae\u4f7f\u7528\u76f4\u63a5\u63d0\u4ea4\u65b9\u6cd5\u4ee3\u66ff sitemap \u63d0\u4ea4\u65b9\u6cd5\u3002<\/li>\n<li>\u63d0\u4ea4\u7684\u7f51\u5740\u9700\u8981\u7b26\u5408\u767e\u5ea6\u7684\u6536\u5f55\u89c4\u8303\u3002<\/li>\n<li>\u63d0\u4ea4\u524d\u540e\uff0c\u767e\u5ea6\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\u8fdb\u884c\u5ba1\u6838\u548c\u6536\u5f55\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55js\u63d0\u4ea4\u6536\u5f55\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u767e\u5ea6\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\u5f00\u653e\u63a5\u53e3\uff0c\u53ef\u76f4\u63a5\u63d0\u4ea4\u7f51\u5740\u6536\u5f55\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a\u83b7\u53d6 access token\u3002\u521b\u5efa submit_url \u8bf7\u6c42\uff0c\u6307\u5b9a url \u548c\u53c2\u6570\u3002\u53d1\u9001\u8bf7\u6c42\uff0c\u5904\u7406\u670d\u52a1\u5668\u54cd\u5e94\u3002\u89e3\u6790\u54cd\u5e94\uff0c\u83b7\u53d6\u63d0\u4ea4\u72b6\u6001\u548c\u4fe1\u606f\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u63d0\u4ea4\u6536\u5f55 \u76f4\u63a5\u63d0\u4ea4\u65b9\u6cd5\uff1a \u901a\u8fc7\u767e\u5ea6\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\u7684\u5f00\u653e\u63a5\u53e3\uff0c\u76f4\u63a5\u63d0\u4ea4\u7f51\u5740\u8fdb\u884c\u6536\u5f55\u7533\u8bf7\u3002 \u5177\u4f53\u6b65\u9aa4\uff1a \u83b7\u53d6 token\uff1a\u4f7f\u7528\u767e\u5ea6\u8d26\u53f7\u767b\u5f55\u641c\u7d22\u8d44\u6e90\u5e73\u53f0\uff0c\u83b7\u53d6 access token\u3002 \u521b\u5efa submit_url \u8bf7\u6c42\uff1a\u4f7f\u7528 fetch API \u6216 XMLHttpRequest \u521b\u5efa\u4e00\u4e2a POST \u8bf7\u6c42\uff0c\u5e76\u6307\u5b9a submit_url API \u7684 URL \u548c\u53c2\u6570\u3002 \u53d1\u9001\u8bf7\u6c42\uff1a\u53d1\u9001\u521b\u5efa\u597d\u7684\u8bf7\u6c42\uff0c\u5e76\u5904\u7406\u670d\u52a1\u5668\u54cd\u5e94\u3002 \u89e3\u6790\u54cd\u5e94\uff1a\u89e3\u6790\u670d\u52a1\u5668\u54cd\u5e94\uff0c\u83b7\u53d6\u63d0\u4ea4\u72b6\u6001\u548c\u76f8\u5e94\u4fe1\u606f\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a async function submitUrl(url, access_token) { const response = await fetch(&#8216;https:\/\/www.baidu.com\/submit\/api\/urlupdate&#8217;, { method: &#8216;POST&#8217;, headers: { &#8216;Content-Type&#8217;: &#8216;application\/json&#8217; }, body: JSON.stringify({ [&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-3375","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3375","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=3375"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3375\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}