簡體   English   中英

更新變量而不刷新PHP

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM