您可以通過一個文件夾中創建一個PHP文件(如果你使用PHP)和使用做到這一點將php文件作爲控件(用於檢索數據)。首先你必須做ajax「Post」呼叫。下面是一些代碼:
$.ajax({
type: "POST",
url: "linktoyourphpfile.php",
data: { refresh: articles },
success: function(data)
{
$("#div-id-where-articles-are-generated").html(data);
}
});
});
現在正在通話後,您可以編輯PHP文件
if (isset($_POST['refresh']) {
// you do the query here. It will be an array. So you need a to define a string and accumulate whatever you need to be written. here's a sample.
$str=""; //first define the string.
$resultset //is the array of the results returned by the database. then loop through it.
foreach($resultset as $res)
{
$str=$str."<div>$res['somethin']</div>"; //you got the point.
}
//then at the end just echo the str.
echo $str;
}