tags:

views:

46

answers:

2

How do you trigger the "error" callback function for jQuery AJAX from JAVA?

A: 

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.

Note that if you are using jsonp, the error callback doesn't work.

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.

Jhong
A: 

See HttpServletResponse.sendError(int sc, String msg)

Maurice Perry
What would happen then in my View when my AJAX assumes the return type to be JSON. According to JAVADOC, the content type is set to "text/html". Will my AJAX trigger the error callback function? Or will my view automagically present a HTML page containing the error?
syker
It will trigger the error callback. An Ajax request is allways done in the background, it never changes the display.
Maurice Perry