AJAX 请求挂起的状态
我有一个按钮,单击后会发送 ajax 请求来触发 PHP 函数,该函数需要一段时间才能完成。我有一个定时函数来检查第一个函数的状态。问题是,这两个函数处于待处理状态,并且计时器上的函数似乎冻结,直到第一个函数完成。
$(document).ready(function() {
var ripstatus;
var intervalID;
$("#ripe_start").click(function() {
if (ripstatus) return;
console.log('started');
$("#ripe_start").addClass("ripe_start_activate");
$("#ripe_start").removeClass("ripe_clickable");
getid('ripe_start').innerHTML = 'Initializing';
ripe_getstatus();
intervalID = window.setInterval(ripe_getstatus(), 500);
})
function ripe_getstatus() {
console.log('getting number ' + ripstatus);
$.get('./?ajax=1&callfunction=returnNumScan', function(data) {
getid('ripe_start').innerHTML = data + ' file(s) left to organize';
});
}
$('#ripe_start').on('transitionend webkitTransitionEnd oTransitionEnd', function() {
console.log('ended');
doextorg();
});
function doextorg() {
if (ripstatus == 1) return;
console.log('exc org processing ' + ripstatus);
ripstatus = 1;
$.ajax({
url: "./?ajax=1&callfunction=organize",
context: document.body
}).done(function(output) {
clearinterval(intervalID);
$("#ripe_start").removeClass("ripe_start_activate");
getid('ripe_start').innerHTML = 'Complete ' + output + ' File(s) organized';
});
} //end function
});
I have a button when clicked send an ajax request to fire a PHP function which takes a while for it to complete. I have a timed function that checks the status of the first function. The problem being is that these two have a status of pending, and the function that is on a timer seems to freeze until the first function is completed.
$(document).ready(function() {
var ripstatus;
var intervalID;
$("#ripe_start").click(function() {
if (ripstatus) return;
console.log('started');
$("#ripe_start").addClass("ripe_start_activate");
$("#ripe_start").removeClass("ripe_clickable");
getid('ripe_start').innerHTML = 'Initializing';
ripe_getstatus();
intervalID = window.setInterval(ripe_getstatus(), 500);
})
function ripe_getstatus() {
console.log('getting number ' + ripstatus);
$.get('./?ajax=1&callfunction=returnNumScan', function(data) {
getid('ripe_start').innerHTML = data + ' file(s) left to organize';
});
}
$('#ripe_start').on('transitionend webkitTransitionEnd oTransitionEnd', function() {
console.log('ended');
doextorg();
});
function doextorg() {
if (ripstatus == 1) return;
console.log('exc org processing ' + ripstatus);
ripstatus = 1;
$.ajax({
url: "./?ajax=1&callfunction=organize",
context: document.body
}).done(function(output) {
clearinterval(intervalID);
$("#ripe_start").removeClass("ripe_start_activate");
getid('ripe_start').innerHTML = 'Complete ' + output + ' File(s) organized';
});
} //end function
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论