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 :
- make ajax call server.
- 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
Post a Comment