Abort DoJo XHR-Request

偶尔善良 提交于 2019-12-10 18:12:17

问题


I'm using the dojo/request/xhr module for HTTP Requests.
Is it possible to abort the active request as it is possible with a XMLHttpRequest?

Thank you in advance, Frank


回答1:


The promise returned by dojo/request/xhr has a cancel method (like normal promises), which aborts the HTTP request.

var request = xhr("foo/bar").then(someHandler, someErrorHandler);
...
if(!request.isResolved()) {
    request.cancel(); // aborts request and triggers the error handler
}

Example here: http://fiddle.jshell.net/QgWNA/



来源:https://stackoverflow.com/questions/21046007/abort-dojo-xhr-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!