Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to a new URL in Javascript with post parameters [duplicate]

I wanted to know if there was any way to navigate to a new URL using JavaScript with POST parameters.

I know with GET you can just append a param string on the URL using window.location.replace()

But is there any way to do this using POST to hide the parameters. Or with jQuery?

like image 994
Stephan Walters Avatar asked Aug 06 '14 16:08

Stephan Walters


1 Answers

No, there isn't. The closest thing you could do is to dynamically create and submit a form, setting its method to POST.

You can always perform a POST request, and then redirect the browser to a new URL via a GET when the post request completes, if you need the request to be a POST request.

Your better bet is to use the appropriate HTTP verb, and not use POST requests as a means of "hiding" parameters. POST requests should be used when you're modifying server state, not when you want prettier URLs.

like image 152
meagar Avatar answered Nov 03 '22 04:11

meagar