7

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?

3
  • redirects by nature are GETs. Commented Aug 6, 2014 at 16:35
  • You can use ajax to post data and set it in session and on ajax success redirect using location.href Commented Aug 6, 2014 at 16:37
  • Only trick you can do is, create a form tag and submit form using $("form").submit() Commented Aug 6, 2014 at 16:56

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ok thanks! This url redirect that i want to do comes right after a POST request..so I guess I have no choice but to do so

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.