how to redirect the browser during an ajax call (made using jQuery) in php -


i facing problem of redirecting site while in ajax call..

here wanna :

  1. make ajax call server.
  2. it goes process, if error occurs, should send error page, else resume.

now problem when in server side, if use :

header('location: error.php'); 

it doesnt redirect page, infact brings data of page (the whole html) javascript success function.

the problem have made generic library both on javascript side (to call ajax) , on server side.

i need redirect page through server side. tried adding js code for

 window.location='error.php'; 

but didnt success

why not return error ajax query can understand instead?

if ($error)  {  header("http/1.1 500 internal server error");     echo "a database error has occurred. etc.etc.";     die();  } 

this trigger ajax request's error callback (if in jquery). echoed text in response body.

you can more fitting status code depending on situation.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -