Skip to content Skip to sidebar Skip to footer

Window.location.replace - Post Version?

window.location.replace() can issue a GET request to target URL and replace the browser 'back' history. Is there any method to issue a POST request to target URL and replace the b

Solution 1:

you might want to do something like these.

 $.ajax({
     url: "your url here",
     type: "POST",
     data: {
         field1: "value1",
         field2: "value2",
         field3: "value3"
     },
     success: function (response) {
         if (response.successFlag) {
             //Replace current location from the history via history APIwindow.history.replaceState({}, 'foo', '/foo');
             window.location = "url of target location here if you want to send a get request";
             $("#form-id").submit();//if you want to post something up
         }
     }
 });

I'm thinking maybe you would also get rid of the need for removing the history using this approach.

OR

you can use the following to replace the record of the current page from the history and submit your form.

window.history.replaceState({}, 'foo', '/foo');
$("#form-id").submit();

OR

you can use the following code when the next page loads and you want to remove the record of the next page from the history:

window.history.replaceState({}, 'foo', '/foo');

Post a Comment for "Window.location.replace - Post Version?"