你们能告诉我如何每隔30秒向一个php脚本发出jquery post请求吗? Php脚本正在向mysql写入一些数据。
$.ajax(
{
type: 'POST',
url: './postIt.php',
data: {
title: 'test',
},
success: function (good)
{
//handle success
//alert(good)
},
failure: function (bad)
{
//handle any errors
//alert(bad)
}
});
答案 0 :(得分:3)
你可以使用set interval来连续轮询。
$(function() {
setInterval(function() {
$.ajax({
type: 'POST',
url: './postIt.php',
data: {
title: 'test',
},
success: function(good) {
//handle success
//alert(good)
},
failure: function(bad) {
//handle any errors
//alert(bad)
}
});
}, 30000);
});
答案 1 :(得分:1)
您可以将setTimeout或setInterval用于此