{"id":49201,"date":"2024-12-02T11:53:28","date_gmt":"2024-12-02T03:53:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49201\/"},"modified":"2024-12-02T11:53:28","modified_gmt":"2024-12-02T03:53:28","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87-ajax-%e5%b0%86%e8%bd%ac%e7%9b%98%e6%8a%bd%e5%a5%96%e7%bb%93%e6%9e%9c%e4%bc%a0%e9%80%81%e5%88%b0-php-%e5%b9%b6%e8%be%93%e5%87%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49201\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241117\/17318135346739609e70aac.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u8f6c\u76d8\u62bd\u5956\u7684 ajax \u4e0e php \u5b9e\u73b0<\/strong><\/p>\n<p>\u5982\u4f55\u901a\u8fc7 ajax \u5c06\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 php \u5e76\u8f93\u51fa\uff1f<\/p>\n<p><strong>\u524d\u7aef\u4ee3\u7801<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u53d1\u9001 ajax \u8bf7\u6c42<\/strong><\/p>\n<pre>$rotaryarrow.click(function() {\n  $.ajax({\n \/\/ \u8bf7\u6c42 url\n url: 'lottery.php',\n \/\/ \u8bf7\u6c42\u7c7b\u578b\n method: 'post',\n \/\/ \u53d1\u9001\u7684\u6570\u636e\n data: {\n   \/\/ \u5177\u4f53\u6570\u636e\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42\n },\n \/\/ ajax \u8bf7\u6c42\u6210\u529f\u540e\u6267\u884c\u7684\u56de\u8c03\n success: function(data, textstatus, jqxhr) {\n   \/\/ \u54cd\u5e94\u7684\u6570\u636e\n   handlelotteryresult(data);\n },\n \/\/ ajax \u8bf7\u6c42\u5931\u8d25\u540e\u6267\u884c\u7684\u56de\u8c03\n error: function(jqxhr, textstatus, errorthrown) {\n   alert('\u62bd\u5956\u5931\u8d25:' + textstatus);\n }\n  });\n});<\/pre>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u62bd\u5956\u7ed3\u679c<\/strong><\/p>\n<pre>function handlelotteryresult(data) {\n  var result = data.result;\n  \/\/ \u6839\u636e\u8fd4\u56de\u7684 result \u8fdb\u884c\u5904\u7406\n  \/\/ \u4f8b\u5982:\n  rotatefunc(result.id, result.angle, result.text);\n}<\/pre>\n<\/li>\n<\/ol>\n<p><strong>php \u4ee3\u7801<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u63a5\u6536\u524d\u7aef\u8bf7\u6c42<\/strong><\/p>\n<pre>$result = $_post['data']; \/\/ \u63a5\u6536\u524d\u7aef\u53d1\u9001\u7684\u6570\u636e<\/pre>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u62bd\u5956\u903b\u8f91<\/strong><\/p>\n<pre>$prizeid = rand(1, 7); \/\/ \u4ea7\u751f\u4e00\u4e2a\u968f\u673a\u6570\n$angle = $prizeid * 45; \/\/ \u8ba1\u7b97\u89d2\u5ea6<\/pre>\n<\/li>\n<li>\n<p><strong>\u8fd4\u56de\u7ed3\u679c<\/strong><\/p>\n<pre>echo json_encode(array(\n  'result' =&gt; array(\n 'id' =&gt; $prizeId,\n 'angle' =&gt; $angle,\n 'text' =&gt; '\u606d\u559c\u4f60\u83b7\u5f97\u4e86...' \/\/ \u5956\u54c1\u6587\u5b57\n  )\n));<\/pre>\n<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5982\u4f55\u901a\u8fc7 AJAX \u5c06\u8f6c\u76d8\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 PHP \u5e76\u8f93\u51fa\uff1f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 \u8f6c\u76d8\u62bd\u5956\u7684 ajax \u4e0e php \u5b9e\u73b0 \u5982\u4f55\u901a\u8fc7 ajax \u5c06\u62bd\u5956\u7ed3\u679c\u4f20\u9001\u5230 php \u5e76\u8f93\u51fa\uff1f \u524d\u7aef\u4ee3\u7801 \u53d1\u9001 ajax \u8bf7\u6c42 $rotaryarrow.click(function() { $.ajax({ \/\/ \u8bf7\u6c42 url url: &#8216;lottery.php&#8217;, \/\/ \u8bf7\u6c42\u7c7b\u578b method: &#8216;post&#8217;, \/\/ \u53d1\u9001\u7684\u6570\u636e data: { \/\/ \u5177\u4f53\u6570\u636e\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42 }, \/\/ ajax \u8bf7\u6c42\u6210\u529f\u540e\u6267\u884c\u7684\u56de\u8c03 success: function(data, textstatus, jqxhr) { \/\/ \u54cd\u5e94\u7684\u6570\u636e handlelotteryresult(data); }, [&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-49201","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49201","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=49201"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49201\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}