1

I have the following function that I use to check for the presence of a login cookie. If the cookie is gone, the user is taken to the public side of the site. The cookie allows the user to remain in the private portion.

I'm using AJAX updates on the private side and what is happening is that after the checkCookie function executes with setInterval, any updates that occur after this point wind up opening a window inside of another window; much like a frame opening inside of another frame. Any updates that occur before this function fires are fine.

When I comment the following code, all updates occur without any issues.

Why is this happening and what can I do to correct this?

  function checkCookie(){
    $.ajax({
      type: "POST",
      url: "/index.php",
      data: "loaded=true",
      dataType: 'json',
      success: function(data){
        if(data.cookie == 0){
          window.location.href = data.href;
        }
      }
    });
  }
  window.setInterval(checkCookie, 60000);
jim
  • 11
  • 1

1 Answers1

0

Setting window.location.href that makes a GET request for the new URL, not POST, therefore using window.location.href it's not possible to send a POST request.

What you have to do is to set up a form tag with data fields in it, set the action attribute of the form to the URL and the method attribute to POST, then call the submit method on the form tag.

(taken from: pass post data with window.location.href)


window.location.reload() reloads the current page with POST data!

And You'll still have to use:

if( $.cookie('cookieName') == null ) {   
   //do something      
}
Community
  • 1
  • 1
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • Thanks roXon but that didn't do anything. I'm still having these windows open inside on each other. I appreciate your answer though. – jim May 31 '11 at 00:20