我目前使用它在 div 中打开新内容(因此我不必刷新整个页面):
文件1.php
<?php
//db connection
if ($res = $mysqli->query("SELECT field FROM table")) {
/* determine number of rows result set */
$row = $res->num_rows;
echo "$row";
$res->close();
}
?>
jQuery.js
$.ajax({
url: "file1.php",
//this will run as soon as the php script echos the answer
success: function(result){
$('#div1').html(result);
}
});
page1.php
<div id="div1">
</div>
代码更新