问题描述
我是比较新的道场,虽然我已经成功地做我的需要的,有一些事情我只是无法弄清楚如何处理它。
简单地说,我有一个表格,当我点击提交按钮请求进入细和在大多数情况下都是很好的。不过,现在我的需要的有在一个div或改变每10秒某些内容或因此而用户一直等待的请求要经过...这就是我想不通该怎么办。
我想放在格的内容是静态的,所以没有必要再要一个请求或类似的任何疯狂内部的请求,我要的是,每隔一段时间内容的变化(例如说我想一个div ,说:你一直在等待X秒和计数)。
希望任何人都可以给我一个手呢?在此先感谢
简单的解决方案将是
- 消防的要求
- 在启动的setInterval做你的东西,或显示装载机GIF或任何
- 当请求返回,撤消在第2部分做了什么。
// 1
VAR REQ = dojo.xhr(/*...*/);
// 2
VAR跨=的setInterval(函数(){
的console.log(等待...); //做的东西
},10000); //时间以毫秒为单位
// 3
功能撤消(){
clearInterval(间);
}
req.then(撤销,撤销); //撤消无论是在sucess或错误
I'm relatively new to dojo, and although I've managed to do all I need, there are certain things I just can't figure out how to do with it.
Simply put, I have a form and when I click the submit button the request goes in fine and for the most part all is good. However, now I want to have in a div or some content that changes every 10 seconds or so while the user been waits for the request to go through... this is what I can't figure out how to do.
The content I want to put in the div is static, so there's no need to have a request inside another request or any madness like that, all I want is that every so often the content changes (eg say I want a div that says "You've been waiting X seconds and counting").
Hopefully anybody can give me a hand with this? Thanks in advance
The simple solution would be
- Fire a request
- Start a setInterval to do your stuff or show a loader gif or whatever
- When the request returns, undo what you did in part 2.
// 1
var req = dojo.xhr( /*...*/ );
// 2
var inter = setInterval(function(){
console.log("waiting..."); //do stuff
}, 10000); //time in miliseconds
//3
function undo(){
clearInterval(inter);
}
req.then(undo, undo); //undo either on sucess or on error
这篇关于如何做一些事情,而一个道场XHR请求正在等待或负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!