我在 gettable.php 中有一个表。该表包含在 index.php 中。我做了一个 AJAX 帖子,我想在帖子完成时用 AJAX 刷新表格。我发现这个:
$(document).ready(function(){
refreshTable();
});
function refreshTable(){
$('#table').load('getTable.php');
setTimeout(refreshTable, 5000);
}
这是我的 AJAX 帖子:
function form(){
var icao = document.getElementById('icao').value;
var name = document.getElementById('name').value;
var weightempty = document.getElementById('weightempty').value;
var weightfull = document.getElementById('weightfull').value;
var cargofull = document.getElementById('cargofull').value;
var cruisespeed = document.getElementById('cruisespeed').value;
var range = document.getElementById('range').value;
var price = document.getElementById('price').value;
var firstclassseats = document.getElementById('firstclassseats').value;
var businessclassseats = document.getElementById('businessclassseats').value;
var economyclassseats = document.getElementById('economyclassseats').value;
ajax.open("POST","new_aircraft_process.php",true);
ajax.onreadystatechange=function(){
if(ajax.readyState==4)
{
var respuesta=ajax.responseText;
document.getElementById('result').innerHTML=ajax.responseText;
$("#newaircraftdialog").dialog('close');
$("#loadingdialog").dialog('close');
//I want to add here the code to refresh the table
}
}
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("icao="+icao+"&name="+name+"&weightempty="+weightempty+"&weightfull="+weightfull+"&cargofull="+cargofull+"&cruisespeed="+cruisespeed+"&range="+range+"&price="+price+"&firstclassseats="+firstclassseats+"&businessclassseats="+businessclassseats+"&economyclassseats="+economyclassseats);
$("#loadingdialog").dialog('open');
}
可以这样做,但只有在我想要每 5 秒一次时才刷新它?