I have a page which depends a number of partial refreshes for interaction. I'm not looking to use a keep session alive mechanism, but I would like to catch error responses to my partial refreshes, alert the user that their session expired / they need to refresh, perform a window.location.reload once they've acknowledged the alert. Specifically, to be event-driven by the user's attempt at a partial refresh (and, by nature, purely through CSJS).
I know from using Chrome DevTools that the partial refresh shows as a Post request, which returns the partial (refresh area) of the html plus any requisite CSJS. I also know that, as documented under Dojo 1.6 in regards to dojo.xhr (Post and Get) supports an error handling parameter, by which I can pass the function I'll want to create. I'm currently uncertain of how to add this function to my dojo.xhrPost requests.
Having seen this XSnippet, "Cache Prevention for Dojo xhr requests", which allows for adding the preventCache option to dojo.xhr requests, I feel this is the right approach. Again, it's the implementation I'm uncertain of. I was disappointed to find that the link it referenced as the source, http://www.juliusbuss.de/web/youatnotes/blog-jb.nsf/dx/a-big-issue-for-mobile-web-apps-with-xpages-for-iphone-and-ipad-and-how-to-solve-it..htm, was not working for me.
Would love a more experienced perspective.
Here is an example how to override the error function for every partialRefresh:
// hijack the dojo function if required
if( !dojo._xhr )
dojo._xhr = dojo.xhr;
var _error;
dojo.xhr = function(){
try{
var args = arguments[1];
_error = args["error"]; // save the original error function
// add your own method
args["error"] = function(arg1, arg2){
alert( "Hello World!" );
_error(arg1, arg2);
}
arguments[1] = args;
}catch(e){}
dojo._xhr( arguments[0], arguments[1], arguments[2] );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With