我的页面上有三个表单,我用ajax提交。有一个名为form2的特定表单,我想自动提交10秒钟。
$(document).ready(function() {
$Addr = localStorage.getItem('eaddress');
$email7 = $('#email7')
if ($Addr !== null) {
$('#email7').val($Addr);
}
if ($Addr != '') {
$.ajax({
type: "POST",
url: "gotopage.php",
data: $("#form2").serialize(),
success: function(data) {
$('#log_msg2').html(data);
var result = $.trim(data);
if (result === "Signing In") {
window.location = 'mypage.html';
}
}
});
}
});
答案 0 :(得分:2)
您可以每隔10秒将此用于AJAX请求:
setInterval(function() {
// Do something every 10 seconds
}, 10000);
答案 1 :(得分:1)
在setInterval函数中调用ajax函数,如:
setInterval(function(){ function }, 3000);
像:
function abc(){
$Addr = localStorage.getItem('eaddress');
$email7 = $('#email7')
if ($Addr !== null) {
$('#email7').val($Addr);
}
if ($Addr != '') {
$.ajax({
type: "POST",
url: "gotopage.php",
data: $("#form2").serialize(),
success: function(data) {
$('#log_msg2').html(data);
var result = $.trim(data);
if (result === "Signing In") {
window.location = 'mypage.html';
}
}
});
}
}
然后调用函数
setInterval(function(){ abc }, 3000);
答案 2 :(得分:0)
你可以在setInterval()
中包装ajax:
$(document).ready(function() {
$Addr = localStorage.getItem('eaddress');
$email7 = $('#email7');
if ($Addr !== null) {
$('#email7').val($Addr);
}
if ($Addr != '') {
setInterval(function() {
$.ajax({
type: "POST",
url: "gotopage.php",
data: $("#form2").serialize(),
success: function(data) {
$('#log_msg2').html(data);
var result = $.trim(data);
if (result === "Signing In") {
window.location = 'mypage.html';
}
}
});
}, 10000);
}
});