我喜欢为我的 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
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)