gpt4 book ai didi

dojo - dojo xhrPost 错误处理程序的 Servlet 响应格式

转载 作者:行者123 更新时间:2023-12-02 00:30:50 25 4
gpt4 key购买 nike

要触发 dojo 的 xhrPost 的错误处理程序,是否有发送服务器响应的特定格式?或者只需在 HttpServletResponse 对象中将状态代码设置为所需的错误代码即可。

谢谢,RR

最佳答案

您只需要在HttpServletResponse 中设置适当的HTTP 状态代码。我认为任何大于或等于 400 的值都会被 XHR 对象视为错误。

当然,您也可以在响应中发送实际内容(通过其输出流)并设置其内容类型。你也会在你的处理程序中收到它:

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
}
});

您还可以从 ioargs.xhr 获取 responseTextstatus,这是完整的 XmlHttpRequest 对象。

关于dojo - dojo xhrPost 错误处理程序的 Servlet 响应格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6932224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com