{"id":183770,"date":"2024-11-10T07:35:18","date_gmt":"2024-11-09T23:35:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183770\/"},"modified":"2024-11-10T07:35:18","modified_gmt":"2024-11-09T23:35:18","slug":"%e4%bd%bf%e7%94%a8jquery%e9%8f%88%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f%e5%8f%8a%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-jquery%e6%96%87%e4%bb%b6%e9%80%a3%e6%8e%a5%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183770\/","title":{"rendered":"\u4f7f\u7528jQuery\u93c8\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u53ca\u6ce8\u610f\u4e8b\u9805 (jquery\u6587\u4ef6\u9023\u63a5\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8jquery%e9%8f%88%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f%e5%8f%8a%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-BEiyQWwoFD\">\u4f7f\u7528jQuery\u93c8\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u53ca\u6ce8\u610f\u4e8b\u9805<\/h1>\n<p>\u5728\u73fe\u4ee3\u7db2\u9801\u958b\u767c\u4e2d\uff0cjQuery\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684JavaScript\u5eab\uff0c\u5e38\u88ab\u7528\u4f86\u7c21\u5316DOM\u64cd\u4f5c\u548c\u4e8b\u4ef6\u8655\u7406\u3002\u7136\u800c\uff0cjQuery\u672c\u8eab\u4e26\u4e0d\u76f4\u63a5\u652f\u6301\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\u3002\u901a\u5e38\uff0c\u6211\u5011\u9700\u8981\u901a\u904eAJAX\u8acb\u6c42\u4f86\u8207\u5f8c\u7aef\u670d\u52d9\u9032\u884c\u4ea4\u4e92\uff0c\u7136\u5f8c\u7531\u5f8c\u7aef\u670d\u52d9\u4f86\u8655\u7406\u6578\u64da\u5eab\u7684\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u4f7f\u7528jQuery\u93c8\u63a5\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\u53ca\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n<h2 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%80%ef%bc%9a%e8%a8%ad%e7%bd%ae%e5%be%8c%e7%ab%af%e7%92%b0%e5%a2%83-BEiyQWwoFD\">\u6b65\u9a5f\u4e00\uff1a\u8a2d\u7f6e\u5f8c\u7aef\u74b0\u5883<\/h2>\n<p>\u5728\u4f7f\u7528jQuery\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8a2d\u7f6e\u4e00\u500b\u5f8c\u7aef\u74b0\u5883\u3002\u9019\u901a\u5e38\u6d89\u53ca\u5230\u9078\u64c7\u4e00\u7a2e\u5f8c\u7aef\u8a9e\u8a00\uff08\u5982PHP\u3001Node.js\u3001Python\u7b49\uff09\u548c\u4e00\u500b\u6578\u64da\u5eab\uff08\u5982MySQL\u3001MongoDB\u7b49\uff09\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528PHP\u548cMySQL\u7684\u57fa\u672c\u8a2d\u7f6e\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u5b89\u88ddPHP\u548cMySQL\u3002<\/li>\n<li>\u5275\u5efa\u4e00\u500b\u6578\u64da\u5eab\u548c\u76f8\u61c9\u7684\u8868\u683c\u3002<\/li>\n<li>\u7de8\u5beb\u4e00\u500bPHP\u8173\u672c\u4f86\u8655\u7406\u6578\u64da\u5eab\u8acb\u6c42\u3002<\/li>\n<\/ol>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684PHP\u8173\u672c\uff0c\u7528\u65bc\u5f9eMySQL\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u6578\u64da\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database_name\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\n$sql = \"SELECT id, name FROM users\";\n$result = $conn-&gt;query($sql);\n\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ \u8f38\u51fa\u6578\u64da\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"name\"]. \"&lt;br&gt;\";\n    }\n} else {\n    echo \"0 results\";\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%a9%9f%e4%ba%8c%ef%bc%9a%e4%bd%bf%e7%94%a8jquery%e7%99%bc%e9%80%81ajax%e8%ab%8b%e6%b1%82-BEiyQWwoFD\">\u6b65\u9a5f\u4e8c\uff1a\u4f7f\u7528jQuery\u767c\u9001AJAX\u8acb\u6c42<\/h2>\n<p>\u4e00\u65e6\u5f8c\u7aef\u74b0\u5883\u8a2d\u7f6e\u5b8c\u6210\uff0c\u63a5\u4e0b\u4f86\u53ef\u4ee5\u4f7f\u7528jQuery\u767c\u9001AJAX\u8acb\u6c42\u4f86\u8207\u5f8c\u7aef\u9032\u884c\u4ea4\u4e92\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528jQuery\u7684\u793a\u4f8b\uff0c\u8a72\u793a\u4f8b\u5411\u5f8c\u7aefPHP\u8173\u672c\u767c\u9001\u8acb\u6c42\u4e26\u7372\u53d6\u6578\u64da\uff1a<\/p>\n<pre><code>&lt;script src=\"https:\/\/code.jquery.com\/jquery-3.6.0.min.js\"&gt;&lt;\/script&gt;\n&lt;script&gt;\n$(document).ready(function(){\n    $.ajax({\n        url: \"your_php_script.php\",\n        type: \"GET\",\n        success: function(data){\n            $(\"#result\").html(data);\n        },\n        error: function(xhr, status, error){\n            console.error(\"AJAX Error: \" + status + error);\n        }\n    });\n});\n&lt;\/script&gt;\n\n&lt;div id=\"result\"&gt;&lt;\/div&gt;<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%89%ef%bc%9a%e8%99%95%e7%90%86%e6%95%b8%e6%93%9a-BEiyQWwoFD\">\u6b65\u9a5f\u4e09\uff1a\u8655\u7406\u6578\u64da<\/h2>\n<p>\u5728\u6210\u529f\u7372\u53d6\u6578\u64da\u5f8c\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u8981\u9032\u884c\u8655\u7406\u548c\u986f\u793a\u3002jQuery\u63d0\u4f9b\u4e86\u591a\u7a2e\u65b9\u6cd5\u4f86\u64cd\u4f5cDOM\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u9019\u4e9b\u65b9\u6cd5\u5c07\u6578\u64da\u52d5\u614b\u986f\u793a\u5728\u7db2\u9801\u4e0a\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-BEiyQWwoFD\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<ul>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u5728\u8655\u7406\u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u52d9\u5fc5\u6ce8\u610fSQL\u6ce8\u5165\u653b\u64ca\u7684\u98a8\u96aa\u3002\u4f7f\u7528\u9810\u8655\u7406\u8a9e\u53e5\u6216ORM\u6846\u67b6\u4f86\u4fdd\u8b77\u60a8\u7684\u61c9\u7528\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u78ba\u4fdd\u5728AJAX\u8acb\u6c42\u4e2d\u6b63\u78ba\u8655\u7406\u932f\u8aa4\uff0c\u4ee5\u4fbf\u7528\u6236\u80fd\u5920\u7372\u5f97\u9069\u7576\u7684\u53cd\u994b\u3002<\/li>\n<li><strong>\u6027\u80fd\uff1a<\/strong>\u5c0d\u65bc\u5927\u91cf\u6578\u64da\u7684\u64cd\u4f5c\uff0c\u8003\u616e\u4f7f\u7528\u5206\u9801\u6216\u61f6\u52a0\u8f09\u6280\u8853\u4f86\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>\u8de8\u57df\u8acb\u6c42\uff1a<\/strong>\u5982\u679c\u60a8\u7684\u524d\u7aef\u548c\u5f8c\u7aef\u4e0d\u5728\u540c\u4e00\u57df\u540d\u4e0b\uff0c\u8acb\u78ba\u4fdd\u6b63\u78ba\u8a2d\u7f6eCORS\uff08\u8de8\u4f86\u6e90\u8cc7\u6e90\u5171\u4eab\uff09\u4ee5\u5141\u8a31AJAX\u8acb\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BEiyQWwoFD\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528jQuery\u93c8\u63a5\u6578\u64da\u5eab\u7684\u904e\u7a0b\u6d89\u53ca\u8a2d\u7f6e\u5f8c\u7aef\u74b0\u5883\u3001\u767c\u9001AJAX\u8acb\u6c42\u4ee5\u53ca\u8655\u7406\u8fd4\u56de\u7684\u6578\u64da\u3002\u901a\u904e\u9075\u5faa\u4e0a\u8ff0\u6b65\u9a5f\u548c\u6ce8\u610f\u4e8b\u9805\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u5be6\u73fe\u524d\u7aef\u8207\u6578\u64da\u5eab\u7684\u4ea4\u4e92\u3002\u82e5\u60a8\u9700\u8981\u7a69\u5b9a\u7684\u4f3a\u670d\u5668\u652f\u6301\u4f86\u904b\u884c\u60a8\u7684\u61c9\u7528\uff0c\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u89e3\u6c7a\u65b9\u6848\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u7684\u6578\u64da\u8655\u7406\u80fd\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u4f7f\u7528jQuery\u93c8\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u53ca\u6ce8\u610f\u4e8b\u9805\uff0c\u78ba\u4fdd\u6578\u64da\u4ea4\u4e92\u5b89\u5168\u9ad8\u6548\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-183770","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183770","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=183770"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183770\/revisions"}],"predecessor-version":[{"id":183771,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183770\/revisions\/183771"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}