php中的ajax新记录计数通知
我正在用php做一个页面,如果输入了任何新记录,它将用新记录计数通知用户屏幕。下面是我为同样的问题所做的代码,但它不能很好地工作。你能告诉我我做错了什么吗php中的ajax新记录计数通知,php,ajax,Php,Ajax,我正在用php做一个页面,如果输入了任何新记录,它将用新记录计数通知用户屏幕。下面是我为同样的问题所做的代码,但它不能很好地工作。你能告诉我我做错了什么吗 alert.php <?php require("config.php"); $result = mysql_query("SELECT * FROM marketing_tend_corr"); $res = mysql_num_rows($result); echo $res; ?> index.ph
alert.php
<?php
require("config.php");
$result = mysql_query("SELECT * FROM marketing_tend_corr");
$res = mysql_num_rows($result);
echo $res;
?>
index.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<?php
define('BASEPATH', true);
require("config.php");
?>
<script>
var count_cases = -1;
setInterval(function(){
$.ajax({
type : "POST",
url : "alert.php",
success : function(response){
if (count_cases != -1 && count_cases != response) echo $count_cases);
count_cases = response;
}
});
},1000);
</script>
alert.php
index.php
var count_cases=-1;
setInterval(函数(){
$.ajax({
类型:“POST”,
url:“alert.php”,
成功:功能(响应){
if(count_cases!=-1&&count_cases!=响应)echo$count_cases);
计数案例=响应;
}
});
},1000);
以下代码行在Javascript中不起作用:
if (count_cases != -1 && count_cases != response) echo $count_cases);
这行代码包含php代码(echo$count_cases),这是服务器端代码
我对代码做了一些修改,并通过返回一个随机值来替换记录数
//alert.php
<?php
echo rand(1, 1000000);
我想你想提醒而不是echoalert在这里工作正常,但我需要作为新消息计数的回音。@SujithNair,但你不能在JavaScription中编写这样的php代码我知道,但有没有办法显示新记录的计数?这实际上工作正常,但我需要显示/打印新记录的数量。。。。。。。。。。。if(计数案例!=-1和计数案例!=响应)警报(“投标营销新记录”);
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
setInterval(function(){
$.ajax({
type : "POST",
url : "alert.php",
success : function(response){
$("body").html(response);
}
});
},1000);
</script>
</head>
<body>
</body>
</html>