View Full Version : Default function for Ajax Response

17 Nov 2009, 1:06 AM
Hello everybody.. is it possible to define a default function for an ajax response?

Cause if the allowed idle time exceeds the php json response will be:

If that happend i want to destroy all components, logout the user and show a simple message box.


17 Nov 2009, 2:25 AM
Well I don't see how you can do that unless you make a client-server sort of mini application.
If I had to make an application that logs the user out automatically after say 5 mins. of 'AFK'ing I would just insert a small code in every page with a setTimeout(). If the settimeout reaches 0, the page sends a Ajax request to the server that hey my user was totally AFK for 5 mins, log him out! And then the page redirects the use to the login page.
This is how I (an ExtJS and JS newb ) would do it.

17 Nov 2009, 2:29 AM
You want any response to any request to be able to return a response that looks like that?

This is a case for class level observability.

Add a requestcomplete listener to the Ext.data.Connection class which traps this special response and logs out.

17 Nov 2009, 2:37 AM
Thx for the reply @ vargadanis: but thats exactly the way i dont wanna solve this problem :)
And Thanks at Animal for the hint. I will try it this way.


Mike Robinson
17 Nov 2009, 9:31 AM
I would add to Animal's suggestion that, if the class listener detects a logout, it should "broadcast a globally-heard event" of some kind to notify every other part of the application that this has just occurred. (I use Saki's msgbus plugin quite extensively these days.)

Since the components of a well-bred application are quite isolated from one another, this gives each one of them a way to know that the barn has just burned down, so they an adjust their part of the user-interface accordingly.

17 Nov 2009, 9:37 AM
I used the Ext.Direct poll to detect if the login was good or not.

Here is the link to a thread in Direct on how my company is using Direct for php session handling.