I want to execute a PHP script using jQuery and terminate jQuery at that point itself. I want the PHP script to be the last page on my browser rather than the jQuery page. I looked it up but every answer included the variable 'data' in it which I don't need. I'm not fetching data from PHP. I want to directly jump from jQuery to PHP and then end the program on the PHP file itself (I don't want to go back to the jQuery page to return some value from the PHP program). How can I do this?
Asked
Active
Viewed 53 times
-2
-
jQuery runs client-side - you cannot "terminate jQuery". If you simply want to switch to another page, use `window.location.href = 'yourfile.php'` – Constantin Groß May 18 '21 at 07:03
-
add `$(location).attr('href', 'http://yoursite.com/file.php')` to your script – Banzay May 18 '21 at 07:03
1 Answers
1
I assume what you want to do is switch to the page ending .php instead of carrying out an ajax request to it and using the result. That doesn't require jquery and is simply done by setting globalThis.location
or its href
property like one of the following:
location = 'adjacent_file.php'
location.href = '/from/root/distant_file.php'
window.location.href = 'https://some.site/path/specific_file.php'
window.location = '... like the others ...'
Which of the above you pick is up to your needs and variable scope, but setting window.location
will probably do you fine.
If you want to make a POST request that lands on the target page, there are a number of good answers already available for this other question - but you will need to create a form through vanilla JS or jquery and then submit it against the target page.

spkrtn
- 1,265
- 10
- 18