我有一个 jQuery 脚本正在运行,它使用以下代码进行定期 AJAX 调用。
var a = moment();
var dayOfMonth = a.format("MMM Do");
var timeSubmitted = a.format("h:mm a");
var count_cases = -1;
var count_claimed = -1;
setInterval(function(){
//check if new lead was added to the db
$.ajax({
type : "POST",
url : "inc/new_lead_alerts_process.php",
dataType: 'json',
cache: false,
success : function(response){
$.getJSON("inc/new_lead_alerts_process.php", function(data) {
if (count_cases != -1 && count_cases != data.count) {
window.location = "new_lead_alerts.php?id="+data.id;
}
count_cases = data.count;
});
}
});
这是每次调用都会运行的 PHP:
$count = mysql_fetch_array(mysql_query("SELECT count(*) as count FROM leads"));
$client_id = mysql_fetch_array(mysql_query("SELECT id, client_id FROM leads ORDER BY id DESC LIMIT 1"));
echo json_encode(array("count" => $count['count'], "id" => $client_id['id'], "client_id" => $client_id['client_id']));
我需要更改代码,以便仅在将新条目添加到数据库时触发警报,而不是在删除现有条目时触发。就目前而言,警报会针对这两个事件触发。
任何帮助是极大的赞赏。