-1

I have this weird issue here where I have the following ajax call inside a file called index.php:

$.ajax({
    method:'post',
    data:
    {
        action: 'del_comment',
        comment_id: comment_id,
    },
    success: function (data) {
        location.reload(true);
    }
});

The PHP portion of the page which intercepts the ajax request is the following:

if($_POST['action'] == 'del_comment') {
    // Do some processing
    die;
}

The issue is that the ajax is executed but when the page is reloaded, the request is a POST instead of a GET. I was under the impression that the following line in the success of my ajax call:

location.reload(true);

Should force a GET request, but it doesn't work. How can I reload the same page with a GET request after the ajax call?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
user765368
  • 19,590
  • 27
  • 96
  • 167
  • 1
    Are you firing your ajax request upon loading the page? – boosted_duck Mar 05 '20 at 00:28
  • 3
    Does this answer your question? [JavaScript to reload the page as GET request](https://stackoverflow.com/questions/1225337/javascript-to-reload-the-page-as-get-request) – j-petty Mar 05 '20 at 00:42
  • @boosted_duck the ajax call is firing on button click – user765368 Mar 05 '20 at 01:24
  • 2
    When in doubt, check the docs! :-) [`.reload()` will do a reload](https://developer.mozilla.org/en-US/docs/Web/API/Location/reload), exactly like hitting the reload button of your browser. If you arrived on the page via POST, hitting the reload button on your browser will do the POST again, and so will `.reload()`. [The standard way to go to a URL](https://stackoverflow.com/questions/948227/should-i-use-window-navigate-or-document-location-in-javascript) is `window.location.href = 'URL';` – Don't Panic Mar 05 '20 at 05:25
  • Why do you want to fire same ajax call with get method again? – Lahiru Madusanka Mar 05 '20 at 09:20

1 Answers1

0

User window.location instead of "location.reload(true);" with the get parameters that you want, you have to create custom URL with parameters and you can use it like (window.location = 'YOUR URL?GET PARAMETER=VALUE';)