Skip to content Skip to sidebar Skip to footer

Browser Ignoring Header Refresh From Ajax Response

In my javascript I have some ajax requests $.getJSON({...}) for various actions. I have a php app that handles these ajax requests. Before processing the actual request, my app f

Solution 1:

AJAX requests don't affect the browser until told to do so. Meaning, if i fetch a page using AJAX, it gets returned, maybe stored in a variable and that's it. It does not do anything after that. You need to parse the return data and act accordingly.

In your case, you might rather return something like JSON, have the client side parse what the return data meant, and act accordingly.

i tend to do something like:

{"directives":{//contains directives what to do first before parsing the data"whatToDo":"redirect"},"payload":{//actual page data}}

Solution 2:

So the file your calling in your request contains the header('Refresh: 0;'); ? Because that has no effect at all, what i would do is if the user is not logged in return an unique string like so:

if (not logged in) {
    echo"NOTLOGGEDIN";
}
else {
    //process request
}

and then in your AJAX request check if they are logged in:

$.get("someURL", function(data) {
    if(data == "NOTLOGGEDIN"){
        //Do something
    } else{
        //Display data
    }
});

Post a Comment for "Browser Ignoring Header Refresh From Ajax Response"