我有這個小腳本來更新報告計數器更新腳本雙打計數器
/*********************************
* Report an ad as inappropriate
* This happens when a user click
* the "Report ad" link on the ad
* view page.
*
* The ad can then be reviewed
* and disabled.
*
* @param int | The ad id
*********************************/
function report_ad($aid) {
$row = $this->db->dbh->query('UPDATE '. $this->config->db_prefix .'_adverts SET been_reported = 1, num_reports = num_reports + 1 WHERE aid = '.$aid.'');
$row->execute();
}
這jQuery來處理鏈接點擊
$("#report-ad").click(function(){
var conf = confirm("Do you want to report this ad as inappropriate?");
var aid = {$smarty.get.aid}
if(conf == true) {
$.ajax({
url: 'reportad.php',
type: 'post',
data: {literal}{aid: aid}{/literal},
success: function(data) {
alert("The ad has been reported as inappropriate");
},
error: function(data) {
alert("An error occured");
}
});
}
return false;
});
reportad.php只包含此:
$adverts = new Adverts();
$adverts->report_ad($_POST["aid"]);
由於某些原因,它更新num_reports與2,所以如果它是1它將變成3,然後5等等。我看不出問題在哪裏。
廣告構造函數調用report_ad()方法嗎? – 2013-04-23 10:31:07
不..不是 – 2013-04-23 10:35:22
看在瀏覽器控制檯....是多個Ajax請求? – charlietfl 2013-04-23 10:40:18