我喜欢为我的 ajax 调用创建一个进度条。 为此,我可以让我的服务器端脚本返回它的进度状态。 所以我需要 javascript 来读取这个进度级别并显示它。
有可能还是我走错路了?
最佳答案
你可以尝试这样的事情(一些伪代码,假设是 jQuery,因为你已经这样标记了问题):
var poll;
$.ajax({
url: 'your_ajax_script',
beforeSend: function(){ // set up out-of-band status polling
poll = setInterval( function(){
$.get('your_script_that_returns_status',
function(data){
update_progressbar(data);
});
}, 1000 ); // update every second?
},
success: function(data) {
clearInterval( poll ); // stop polling
finalize_or_hide_progressbar(); // clean up
do_something_with( data ); // your "done" logic
}
});
关于javascript - AJAX 以渐进的方式读取数据,而不仅仅是在完成时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4069641/