[support] API invoke during page refresh

Kamal Palei palei.kamal at gmail.com
Tue Sep 25 02:16:06 UTC 2012


Hi Jamie Holly
This was really a wondeful solution. I had to modify a bit as below. In
hook_init(), I added below code and was able to get the result as expected.

*    if(isset($_SERVER['REDIRECT_URL']))
    {
        if($_SERVER['REDIRECT_URL'] == '/mysite.com/system/ajax')
        {
            // Page requested via jQuery - AJAX. No need to reset
my session variables
        }
        else if($_SERVER['REDIRECT_URL'] == '/
mysite.com/my_custom_module/form/register')
        {
            // Non jQuery-AJAX page request. This is the place to reset
my session variables
        }
    }    *
**

 Thanks a lot.

Kamal
Net Cloud Systems
Bangalore



On Tue, Sep 25, 2012 at 6:16 AM, Jamie Holly <hovercrafter at earthlink.net>wrote:

>  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 Hollyhttp://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> wrote:
>
>>
>> http://api.drupal.org/api/drupal/modules!system!system.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/ ]
>>
>
>
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20120925/2253876c/attachment.html 


More information about the support mailing list