Home » Php » How can I redirect my Window page to another URL from the ajax called php function, I dont want to redirect it from jQuery or javascript

How can I redirect my Window page to another URL from the ajax called php function, I dont want to redirect it from jQuery or javascript

Posted by: admin February 23, 2020 Leave a comment

Questions:

I have a main page url localhost/php/coadlines/home.php and hiting an ajax localhost/php/coadlines/processAjax.php but in processAjax.php page I want to some redirection function, so that My main page url ie.localhost/php/coadlines/home.php redirect to localhost/php/coadlines/index.php.
I dont want to write any redirection function in ajax success callback function like (window.location.replace()).

NOTE:ALL i need to do redirect it from PHP only dont want to do it from jQuery and javascript redirection.

How to&Answers:

Short answer: you can’t.

Long answer: you already finished sending the page, and it’s in the browser’s control now. If you want to add information (like a redirect), you have to do it using the javascript that’s running on that page.

As a workaround, you might be able to instruct the first page to redirect after a delay, as described here. This is not-standard, not guaranteed to work, and does not guarantee that the ajax request finishes, but it might work for you use case. But if in any possible: use javascript.