[英]Update a variable without refresh in PHP
我需要自动更新一个名为$count
的变量(在下面的代码中)。 当我的数据库更新时,因为我需要在Android应用程序中使用$count
值,所以$count
会立即更新,因此我无法每次都刷新count.php
文件。
<?php
$con=mysql_connect("","","");
mysql_select_db("u607509006_bd1",$con);
$query = "select * from content where status='a'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
echo $count;
mysql_close($con);
?>
只需在客户端使用Jquery Ajax请求即可 ,如下所示:
$.ajax({
url: "path/to/code/file.php" // change this to your path to your code
}).done(function(data) {
// This is executed after the ajax request is complete
// data should be the updated value. You can also return other data // types e.g. JOSN
$('#counter').text(data);
});
JS小提琴示例: https : //jsfiddle.net/anik786/nvkdLhv2/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.