[support] API invoke during page refresh

Jamie Holly hovercrafter at earthlink.net
Tue Sep 25 00:46:55 UTC 2012


There really isn't an API that exists just for that purpose. Remember, 
AJAX is also just a simple page load.

One workaround is to check for the HTTP_X_REQUESTED_WITH header. JQuery 
adds that in on all AJAX requests, so as long as you don't have any 
modules doing their own AJAX or changing the jQuery AJAX setup, it 
should work (modules invoking their own AJAX would be a fringe case).

So in hook_init, just go with something like:

if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
     // Page requested via jQuery - AJAX.
} else {
   // Non jQuery-AJAX page request.
}

Jamie Holly
http://www.intoxination.net
http://www.hollyit.net

On 9/24/2012 8:28 PM, Kamal Palei wrote:
> Hi Nancy
> Thanks for help.
> Initially I thought so and gave a try for _init() hook. It looks it 
> gets called always either it is first time page load, or a page 
> refresh 9F5 in windows env) or even during AJAX events. Even I tried 
> _exit() hook, looks it is also invoked always.
> I am looking for a hook that gets invoked for first time page load 
> and on page refresh, but should not be invoked during AJAX events.
> So still searching if any such hooks are available that gets invoked 
> only during *first time page load and on page refresh*.
> Thanks
> Kamal
> Net Cloud Systems
> Bangalore
>
> On Mon, Sep 24, 2012 at 4:03 PM, Ms. Nancy Wichmann 
> <nan_wich at bellsouth.net <mailto:nan_wich at bellsouth.net>> wrote:
>
>     http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_init/7
>     <http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_init/7>
>
>
>     /*Nancy
>     */
>     Injustice anywhere is a threat to justice everywhere. -- Dr.
>     Martin L. King, Jr.
>
>         ------------------------------------------------------------------------
>         *From:* Kamal Palei
>
>         Hi List
>         I want to know is there any API in D7 is invoked when a page
>         loads for first time or during page refresh/reload.
>         During anyother time that particular api should not be invoked.
>         I have a custom form, and I keep certain variables in
>         $_SESSION. During first time page loads I want to reset the
>         session variables.
>         Also during page refresh (for windows IE F5) also I want to
>         reset session variables.
>
>
>     --
>     [ Drupal support list | http://lists.drupal.org/ ]
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20120924/6e135f21/attachment.html 


More information about the support mailing list