To trigger the error handler for dojo's xhrPost
, is there a specific format in which the server response is to be se开发者_如何学Pythonnt? Or just setting the status code to the required error code in the HttpServletResponse
object does the work.
Thanks, RR
You only need to set the appropiate HTTP status code in the HttpServletResponse
. I think anything greater than or equal to 400 will be considered an error by the XHR object.
Of course you can also send actual content in your response (via its output stream) and set its content type. You'll receive that in your handler as well:
dojo.xhrPost({
url: '/request',
load: function(data, ioargs) { /* ... */ },
error: function(error, ioargs) {
// error is a Javascript Error() object, but also contains
// some other data filled in by Dojo
var content = error.responseText; // response as text
var status = error.status; // status code
}
});
You can also get responseText
and status
from ioargs.xhr
, which is the full XmlHttpRequest
object.
精彩评论