Ajax Error Handling¶
Transition to the error screen may be required when non recoverable error is returned at the Ajax communication destination.The mechanism and the implementation method for transiting to the error screen in such cases in described here.
Items
Mechanism for transiting to the Error screen¶
httpXXX.jsp (like http500.jsp, http401.jsp) is called when an exception is thrown at server side.In case of Ajax request, the error is not displayed on the screen since httpXXX.jsp response closes in Ajax.Following mechanism is implemented for transiting to the error screen even on the request of Ajax.
- While sending the Ajax request, set x-jp-co-intra-mart-ajax-request-from-imui-form-util = true in HTTP Header.
- When an exception is thrown at the server, x-jp-co-intra-mart-ajax-request-to-imui-form-util = true is set to HTTP Header for httpXXX.jsp and error information is returned as JSON.
- Since x-jp-co-intra-mart-ajax-request-to-imui-form-util exists in HTTP Header at $.ajax error, error information is passed. Set the error information in Form and submit it to the original screen (httpXXX.jsp).
- Exception thrown at the server is displayed on the screen.
Implementation Method¶
Specify the following in headers, error of jQuery.ajax.$.ajax({ ..., headers: { 'x-jp-co-intra-mart-ajax-request-from-imui-form-util': 'true' }, error: imuiTransitionToErrorPage, ... });By implementing in this way, the user can transit to the error screen when the exception is thrown at the server.
To transit to the error screen while executing independent error handling¶
In the above sample, it only transits to the Error screen and does not perform the other processes.Following implementation can be done to add the independent process.$.ajax({ ..., headers: { 'x-jp-co-intra-mart-ajax-request-from-imui-form-util': 'true' }, error: function(XMLHttpRequest, textStatus, errorThrown) { // // Execute the independent process // imuiTransitionToErrorPage(jqXHR, textStatus, errorThrown); }, ... });