6

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?

fejese
  • 4,353
  • 4
  • 25
  • 35
Stephan Walters
  • 333
  • 2
  • 12

1 Answers1

2

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.

meager
  • 209,754
  • 38
  • 307
  • 315