I know its a bit stupid question which is a bit meaningless but still I wanted to know is there any way to track last ajax call on page.
Actually the issue is I developed an application which works with ajax and many ajax calls happening with different different actions but if no ajax request call for 10 mins. it will expire session but I don't want it on just ajax call.
What I Want
if no activity happens in 10 mins. I don't wanna do anything but if even any click or keyboard activity happens then it will make 1 more ajax in after 10 mins. of click so session will not expire.
But that's not the issue to write script for it but the issue is I've lots of page and lots of different ajax call's so I just want to track last ajax call time on page.
I don't know if there's any possible way or not for it so I didn't write any code yet if any its possible then I'll start writing script otherwise I'll find another way but I appreciate if someone suggest me a way to do it.
Thanks
You can use ajaxsetup
and increment a variable in ajaxsetup
. Because ajaxsetup
call in every ajax
call
see the documentation of ajaxsetup http://api.jquery.com/jquery.ajaxsetup/
If you want your session not to expire, then increase its duration :
Adding this to your script will set php sessions lifetime to a month :
ini_set('session.gc_maxlifetime', 2678400);
ini_set('session.cookie_lifetime', 2678400);
EDIT for comment below :
To track last call add this at the beginning of your application entry point :
<?php
session_start();
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
$_SESSION['last_ajax_call'] = time();
}
declare one variable and set 0 at the end of ajax request and change the value of variable as per time
i think this will help you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.