Search code examples
dojoxmlhttprequestabort

Abort DoJo XHR-Request


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


Solution

  • 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/