How do you trigger the "error" callback function for jQuery AJAX from JAVA?
如何从JAVA触发jQuery AJAX的“错误”回调函数?
2 个解决方案
#1
1
See HttpServletResponse.sendError(int sc, String msg)
请参阅HttpServletResponse.sendError(int sc,String msg)
#2
0
Nothing specific to Java... You just need to send output that was not expected (i.e. non-xml if you specify that the input should be xml in the jQuery ajax call), or return a header other than http 200.
没有特定于Java ...你只需要发送不期望的输出(例如,如果你指定输入应该是jQuery ajax调用中的xml,则为非xml),或者返回除http 200以外的标头。
Note that if you are using jsonp, the error callback doesn't work.
请注意,如果您使用的是jsonp,则错误回调不起作用。
If you want to trigger an application error, you might be better off returning an error code as part of your data, and then process the error in the success callback function.
如果要触发应用程序错误,最好将错误代码作为数据的一部分返回,然后在成功回调函数中处理错误。
#1
1
See HttpServletResponse.sendError(int sc, String msg)
请参阅HttpServletResponse.sendError(int sc,String msg)
#2
0
Nothing specific to Java... You just need to send output that was not expected (i.e. non-xml if you specify that the input should be xml in the jQuery ajax call), or return a header other than http 200.
没有特定于Java ...你只需要发送不期望的输出(例如,如果你指定输入应该是jQuery ajax调用中的xml,则为非xml),或者返回除http 200以外的标头。
Note that if you are using jsonp, the error callback doesn't work.
请注意,如果您使用的是jsonp,则错误回调不起作用。
If you want to trigger an application error, you might be better off returning an error code as part of your data, and then process the error in the success callback function.
如果要触发应用程序错误,最好将错误代码作为数据的一部分返回,然后在成功回调函数中处理错误。