{"id":746,"date":"2012-08-19T21:06:07","date_gmt":"2012-08-19T13:06:07","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=746"},"modified":"2012-08-19T21:06:07","modified_gmt":"2012-08-19T13:06:07","slug":"phpjqueryajax%e5%ae%9e%e7%8e%b0%e6%96%87%e7%ab%a0%e9%a1%b6%e8%b8%a9%e8%b5%9e%e7%9a%84%e5%ae%9e%e6%97%b6%e6%95%b0%e6%8d%ae%e6%98%be%e7%a4%ba","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/746","title":{"rendered":"[php+jquery+ajax]\u5b9e\u73b0\u6587\u7ae0\u9876\u8e29\u8d5e\u7684\u5b9e\u65f6\u6570\u636e\u663e\u793a"},"content":{"rendered":"

\"php\u9876\u8e29\u7684\u8bbe\u8ba1\"<\/a><\/p>\n

\u4e0a\u56fe\u5c31\u662f\u6211\u7684\u8bbe\u8ba1\u7684\u6700\u7ec8\u7ed3\u679c\u3002<\/p>\n

\u5148\u662f\u6570\u636e\u5e93\u8bbe\u8ba1\uff0c\u5bf9\u5e94\u8be5\u6587\u7ae0\u7684\u8bb0\u5f55\u4e2d\u6709\u4e24\u4e2a\u5b57\u6bb5\uff0c\u5206\u522b\u5bf9\u5bf9\u5e94\u9876\u548c\u8e29\u3002<\/p>\n

\u5148\u770bhtml\u9875\u9762\u4ee3\u7801\uff1a<\/p>\n

<tr>
\n<td align=”center”><span id=”ding” style=” font-weight:bold; font-size:36px;font-family:Georgia, “Times New Roman”, Times, serif;”><img src=”templates\/images\/ding.gif” \/>\u9876\u4e00\u62f3(<span id=”dingnum”>{$data_main.0.num_ding}<\/span>)<\/span><\/td>
\n<td align=”center”><span id=”cai” style=” font-weight:bold;font-size:36px;font-family:Georgia, “Times New Roman”, Times, serif;”><img src=”templates\/images\/cai.gif” \/>\u8e29\u4e00\u811a(<span id=”cainum”>{$data_main.0.num_cai}<\/span>)<\/span><\/td>
\n<\/tr><\/p>\n

 <\/p><\/blockquote>\n

 <\/p>\n

\u518d\u770b\u5bf9\u5e94\u7684jquery \u4ee3\u7801\uff08\u53ea\u4ee5\u9876\u793a\u4f8b\uff09\uff1a<\/p>\n

\/\/ding
\n$(document).ready(function(){
\n$(“#ding”).click(function(){
\nvar pid=$(“#pid”).val();
\n\/\/alert(pid);
\nvar dinged=parseInt($(“#dingnum”).html())+1;
\n\/\/alert(dinged);
\n$(“#dingnum”).load(“ding.php?pid=”+pid+”&num_ding=”+dinged);<\/p>\n

})
\n});<\/p><\/blockquote>\n

\u5176\u4e2d\u7684pid\u662f\u6211\u7684\u6587\u7ae0id\u3002$(“#dingnum”).load(“ding.php?pid=”+pid+”&num_ding=”+dinged)\uff0c\u8fd9\u4e00\u53e5\u662fjquery\u4e2dajax\u7684\u5178\u578b\u5e94\u7528\uff0c\u8fd9\u5176\u5b9e\u5c31\u662f\u8fd4\u56de\u5bf9\u5e94\u9875\u9762\u7684\u6700\u7ec8\u8fd4\u56de\u503c\u3002\u5b9e\u4f8b\u5316\u4e00\u4e0b\u5c31\u662f\uff1ading.php?pid=345&num_ding=87.\u90a3\u6211\u8fd9\u4e2ading.php\u662f\u6700\u7ec8\u8fd4\u56de\u4e86\u5f53\u524d\u8fd9\u4e2a\u6587\u7ae0\u88ab\u9876\u8fc7\u7684\u6b21\u6570\u3002\u901a\u8fc7jquery\u7684\u5f3a\u5927\u7684load\u51fd\u6570\u53d6\u5f97\u5f53\u524d\u503c\uff0c\u5e76\u5728html\u9875\u9762\u6700\u7ec8\u5448\u73b0\u51fa\u6765\u3002<\/p>\n

\u518d\u770b\u4e00\u4e0bding.php\u8fd9\u4e2a\u9875\u9762\u4ee3\u7801\uff0c\u5176\u5b9e\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n

<?php
\n\/\/\u8fd9\u4e2a\u662f\u9876\u8e29\u9875\u9762\u4e13\u7528\u7684
\nrequire(‘conn.php’);
\n\/\/\u5f97\u5230\u8981\u64cd\u4f5c\u7684\u6570\u636eid
\n$pid=$_GET[pid];
\n$num_ding=$_GET[num_ding];<\/p>\n

\/\/$result=mysql_fetch_array(mysql_query(“select * from gif_article where id=’$pid'”));<\/p>\n

$update=mysql_query(“update gif_article set num_ding=$num_ding where id=’$pid'”);<\/p>\n

$result=mysql_fetch_array(mysql_query(“select * from gif_article where id=’$pid'”));<\/p>\n

echo $result[num_ding];<\/p>\n

?><\/p>\n

 <\/p><\/blockquote>\n

\u5176\u5b9e\u6211\u8fd9\u4e2ading.php\u9875\u9762\u662f\u6709\u591a\u4f59\u4ee3\u7801\u7684\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e00\u4e0b\uff1aget\u53d6\u5f97\u7684\u503c\u5176\u5b9e\u5c31\u662f\u6700\u540e\u53c8\u8fd4\u56de\u7684\u503c\uff0c\u5475\u5475\u3002\u7531\u4e8e \u6211\u662f\u4e2a\u4eba\u7528\u7684\uff0c\u6240\u4ee5\u6211\u5c31\u4e0d\u6539\u4e86\u3002\u5982\u679c\u4f60\u662f\u7ed9\u4eba\u5bb6\u516c\u53f8\u505a\u4e8b\u7684\uff0c\u8fd8\u662f\u4e25\u8c28\u4e00\u4e9b\u597d\u5566\u3002\u800c\u4e14\u6211\u7684\u9876\u8e29\u662f\u7528\u76842\u4e2aphp\u9875\u9762\u6765\u5b9e\u73b0\u7684\uff0c\u5b8c\u5168\u53ef\u4ee5\u878d\u5408\u6210\u4e00\u4e2a\u5355\u72ec\u9875\u9762\u7684\u2026\u2026<\/p>\n

 <\/p>\n

\u518d\u4e0a\u90a3\u4e2a\u7ea2\u84dd\u8272\u7684\u9876\u8e29\u6b21\u6570\u5bf9\u6bd4\u6f14\u793a\u3002\u4e5f\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u662f\u5229\u7528td \u7684\u5bbd\u5ea6\u6765\u505a\u533a\u5206\u7684\u3002look:<\/p>\n

<tr>
\n<td bgcolor=”#FF0000″ width=”{$data_main.0.num_ding}\/({$data_main.0.num_ding}+{$data_main.0.num_cai})”>&nbsp;<\/td>
\n<td bgcolor=”#0000FF” width=”{$data_main.0.num_cai}\/({$data_main.0.num_ding}+{$data_main.0.num_cai})”>&nbsp;<\/td>
\n<\/tr><\/p><\/blockquote>\n

 <\/p>\n

 <\/p>\n

\u6700\u540e\u7684\u603b\u7ed3\u5c31\u662fjquery\u592a\u5f3a\u5927\u4e86\uff0c\u800c\u4e14\u975e\u5e38\u6613\u5b66\u6613\u7528\uff01\u8fd9\u90fd \u662f\u56fd\u5916\u8d27\uff01\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e0a\u56fe\u5c31\u662f\u6211\u7684\u8bbe\u8ba1\u7684\u6700\u7ec8\u7ed3\u679c\u3002 \u5148\u662f\u6570\u636e\u5e93\u8bbe\u8ba1\uff0c\u5bf9\u5e94\u8be5\u6587\u7ae0\u7684\u8bb0\u5f55\u4e2d\u6709\u4e24\u4e2a\u5b57\u6bb5\uff0c\u5206\u522b\u5bf9\u5bf9\u5e94\u9876\u548c\u8e29\u3002 \u5148\u770bhtml\u9875\u9762\u4ee3\u7801\uff1a <tr> <td align=”center”><span id=”ding” style=” font-weight:bold; font-size:36px;font-family:Georgia, “Times New Roman”, Times, serif;”><img src=”templates\/images\/di<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,9],"tags":[129],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/746"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":2,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":749,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/746\/revisions\/749"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}