1

In javascript normaly page redirection can be done as follow with a parameter.

window.location = "add-new-cos.jsp?id="+id;

but this id value is send to the next page with in the GET method. but i want to send it with the POST method. is there any way to do it with javascript....?

2

4 Answers 4

8

Not as easy as the window.location redirect but easy enough :)

var form = document.createElement("form");
    input = document.createElement("input");

form.action = "add-new-cos.jsp";
form.method = "post"

input.type = "hidden";
input.name = "id";
input.value = id;
form.appendChild(input);

document.body.appendChild(form);
form.submit();
6

Sending POST data is avaliable either on submitting form or via ajax request. You may try to create an invisible form with hidden fields with correct names and values and submit it by javascript when needed.

1
  • Invisible form is what many payment gateways(that I've seen) use to redirect.
    – Prasanth
    Dec 3, 2012 at 6:48
0

You can put the id in a form, use document.forms["myform"].submit(); and returns a redirect action in your request handler on server.

0

Using window.location.href it's not possible to send a POST request.

What you have to do is to set up a form tag with data fields in it, set the action attribute of the form to the URL and the method attribute to POST, then call the submit method on the form tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.