{"id":3379,"date":"2024-11-10T11:19:24","date_gmt":"2024-11-10T03:19:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3379\/"},"modified":"2024-11-10T11:19:24","modified_gmt":"2024-11-10T03:19:24","slug":"js-%e5%a6%82%e4%bd%95%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3379\/","title":{"rendered":"js \u5982\u4f55\u64cd\u4f5c\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  javascript \u5229\u7528 xmlhttprequest \u5bf9\u8c61\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u4f7f\u7528 sql.js \u5e93\u6267\u884c sql \u67e5\u8be2\uff0c\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u53ef\u901a\u8fc7\u5faa\u73af\u904d\u5386\u8bbf\u95ee\u6bcf\u4e2a\u7ed3\u679c\u3002\u6b64\u5916\uff0cjavascript \u652f\u6301\u4f7f\u7528 sql.js \u66f4\u65b0\u6570\u636e\u5e93\uff0c\u5e76\u5728\u4f7f\u7528\u5b8c\u540e\u5173\u95ed\u8fde\u63a5\u4ee5\u91ca\u653e\u8d44\u6e90\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110811095914539.jpg\" class=\"aligncenter\" title=\"js \u5982\u4f55\u64cd\u4f5c\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"js \u5982\u4f55\u64cd\u4f5c\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u64cd\u4f5c\u6570\u636e\u5e93<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>JavaScript \u662f\u4e00\u79cd\u6d41\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8e Web \u5f00\u53d1\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u5904\u7406\u5404\u79cd\u4efb\u52a1\uff0c\u5305\u62ec\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 JavaScript \u8fde\u63a5\u548c\u67e5\u8be2\u6570\u636e\u5e93\u3002<\/p>\n<p><strong>\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u7684 XMLHttpRequest \u5bf9\u8c61\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre>let xhr = new XMLHttpRequest();\nxhr.open('GET', 'data.json');\nxhr.send();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u5c06\u5411 data.json \u6587\u4ef6\u53d1\u9001\u4e00\u4e2a GET \u8bf7\u6c42\uff0c\u4ee5\u4ece JSON \u6587\u4ef6\u4e2d\u83b7\u53d6\u6570\u636e\u5e93\u6570\u636e\u3002<\/p>\n<p><strong>\u67e5\u8be2\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4e00\u65e6\u5efa\u7acb\u4e86\u8fde\u63a5\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 SQL \u67e5\u8be2\u6570\u636e\u5e93\u3002JavaScript \u4f7f\u7528 SQL.js \u5e93\u8fdb\u884c SQL \u67e5\u8be2\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 SQL.js \u67e5\u8be2\u6570\u636e\u5e93\uff1a<\/p>\n<pre>let db = new SQL.Database();\nlet results = db.exec('SELECT * FROM table_name');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u5c06\u4ece\u540d\u4e3a table_name \u7684\u8868\u4e2d\u9009\u62e9\u6240\u6709\u884c\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728 results \u53d8\u91cf\u4e2d\u3002<\/p>\n<p><strong>\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c<\/strong><\/p>\n<p>\u67e5\u8be2\u7ed3\u679c\u662f\u4e00\u4e2a\u5305\u542b\u67e5\u8be2\u7ed3\u679c\u6570\u636e\u7684\u6570\u7ec4\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u8bbf\u95ee\u6bcf\u4e2a\u7ed3\u679c\uff1a<\/p>\n<pre>for (let row of results) {\n  console.log(row);\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u5c06\u6253\u5370\u67e5\u8be2\u7ed3\u679c\u7684\u6bcf\u4e00\u884c\u3002<\/p>\n<p><strong>\u66f4\u65b0\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u9664\u4e86\u67e5\u8be2\u6570\u636e\u5e93\u4e4b\u5916\uff0cJavaScript \u8fd8\u53ef\u4ee5\u7528\u6765\u66f4\u65b0\u6570\u636e\u5e93\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 SQL.js \u66f4\u65b0\u6570\u636e\u5e93\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>db.run('UPDATE table_name SET column_name = new_value');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u5c06\u66f4\u65b0 table_name \u8868\u4e2d column_name \u5217\u7684\u503c\u3002<\/p>\n<p><strong>\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u4f7f\u7528\u5b8c\u6570\u636e\u5e93\u540e\uff0c\u5e94\u5173\u95ed\u8fde\u63a5\u4ee5\u91ca\u653e\u8d44\u6e90\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5173\u95ed\u8fde\u63a5\uff1a<\/p>\n<pre>db.close();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs \u5982\u4f55\u64cd\u4f5c\u6570\u636e\u5e93\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>javascript \u5229\u7528 xmlhttprequest \u5bf9\u8c61\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u4f7f\u7528 sql.js \u5e93\u6267\u884c sql \u67e5\u8be2\uff0c\u8bbf\u95ee\u67e5\u8be2\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u53ef\u901a\u8fc7\u5faa\u73af\u904d\u5386\u8bbf\u95ee\u6bcf\u4e2a\u7ed3\u679c\u3002\u6b64\u5916\uff0cjavascript \u652f\u6301\u4f7f\u7528 sql.js \u66f4\u65b0\u6570\u636e\u5e93\uff0c\u5e76\u5728\u4f7f\u7528\u5b8c\u540e\u5173\u95ed\u8fde\u63a5\u4ee5\u91ca\u653e\u8d44\u6e90\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u64cd\u4f5c\u6570\u636e\u5e93 \u5f15\u8a00 JavaScript \u662f\u4e00\u79cd\u6d41\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8e Web \u5f00\u53d1\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u5904\u7406\u5404\u79cd\u4efb\u52a1\uff0c\u5305\u62ec\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 JavaScript \u8fde\u63a5\u548c\u67e5\u8be2\u6570\u636e\u5e93\u3002 \u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5 \u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u7684 XMLHttpRequest \u5bf9\u8c61\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a let xhr = new XMLHttpRequest(); xhr.open(&#8216;GET&#8217;, &#8216;data.json&#8217;); xhr.send(); \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u9762\u4ee3\u7801\u5c06\u5411 data.json \u6587\u4ef6\u53d1\u9001\u4e00\u4e2a GET \u8bf7\u6c42\uff0c\u4ee5\u4ece JSON \u6587\u4ef6\u4e2d\u83b7\u53d6\u6570\u636e\u5e93\u6570\u636e\u3002 \u67e5\u8be2\u6570\u636e\u5e93 \u4e00\u65e6\u5efa\u7acb\u4e86\u8fde\u63a5\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 SQL \u67e5\u8be2\u6570\u636e\u5e93\u3002JavaScript \u4f7f\u7528 SQL.js \u5e93\u8fdb\u884c SQL \u67e5\u8be2\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 SQL.js \u67e5\u8be2\u6570\u636e\u5e93\uff1a let [&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-3379","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3379","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=3379"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3379\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}