Documentation for JQAjaxSetup>>onError: says:
onError: anObject "A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are 'timeout', 'error', 'notmodified' and 'parsererror'."
I'd like to display the error message using something like
anAjax onError: ((html jQuery id: someId) before: (MyInstanceOfWAPainter error: 'An error message'));
How do I do that? Possibly doing it all on the client side.
Because the error happens client-side and you probably have a failing connection in such an event, you need to generate the complete javascript code that will display the error (i.e. without rendering callbacks to Seaside).
The snippet below will generate a JS function with two arguments. The body of the function is the jQuery expression that will put the error message (inside the _error
variable) right before the html dom element with id someId
.
anAjax
onError: (((html jQuery id: someId) before: (JSStream on: '_error'))
asFunction: #('_XMLHttpRequest' '_error'));
Personally, I would not use Seaside's JS-generation functionality here if the id in someId
is not dynamically generated. If it's dynamically generated from within Seaside, the first snippet might still be easier.
anAjax onError: (JSStream on: 'function(_XMLHttpRequest,_error){
$(''#someId'').before(_error)})