0

I'm using jquery Ajax function to process a user login in a jquery pop up modal. Simplemodal. The script posts the username and password then displays the out come in a hidden div using jquery .show function. The question is in my login script it posts data back fine but how can I redirect the user if there login is successful. Normally I would use a php header but that doesn't reload tr close the modal popup just loads the header into the popup.

Can anyone help.

Thanks

Benjio
  • 73
  • 1
  • 11
  • It's JavaScript, so redirect user in one of possible ways. More: http://ntt.cc/2008/01/21/5-ways-to-redirect-url-with-javascript.html – Sean Doe Dec 21 '13 at 21:59

2 Answers2

3

Send back your data to the ajax response as an array with a status inside of it.

if(logic to determine login was false){
    return json_encode(array('status' => false, 'action' => 'path/to/redirect/to'));
}

Then in your response, evaluate the status.

success:function(data){
    if(data.status == false){ 
        window.location = data.action;
    }
}
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
0

How about:

document.location.href='/newpage/';

Or:

window.location = '/newpage/';

either one works.

Bryan Elliott
  • 4,055
  • 2
  • 21
  • 22
  • Thanks but I know how to redirect but needed to redirect Oma. Return condition like above :) thanks – Benjio Dec 21 '13 at 22:10