Hi all,

I'm trying to write a global AJAX response handler which hooks in
*before* the client code receives requested data. The response data
from the server might be in JSON or HTML format depending on where the
request has come from.

I'm trying to build in some client-side handling in case the user's
login session ends between page load and asynchronous request. The
server-side is easy - if the request wants JSON just return
"{login_required: true}", if HTML then something like "<span
id="login_required"></span>" should work for the equivalent.

I have 2 issues here:
1. The global AJAX event "ajaxSuccess" is being generated after the
local AJAX event "success". This means that I can't just prevent the
"success" handler from running and call the "error" one instead.
2. Even if I can intercept the events / response in a generic handler
before it is passed to the request-specific handler, I won't know
whether I've got HTML or JSON data.

The other option I can think of is in each response-handler function,
call e.g. 'checkResponse(data, type)' function which does the
necessary checking and returns true/false for ok/not-ok. That seems
risky though as anyone adding a feature which uses async. requests
might forget to use the check function. Obviously I can't defend
against all eventualities but this idea is a bit lacking in 'defensive
programming'.

I know this is a little vague...has anyone implemented this sort of
thing before? Cna anyone point me in the right direction for how to
implement this? I feel like I'm approaching it wrong...

TIA
--rob

Reply via email to