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....?
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....?
Share Improve this question edited Dec 3, 2012 at 6:43 Andreas 21.9k7 gold badges51 silver badges58 bronze badges asked Dec 3, 2012 at 6:41 rajuraju 111 gold badge1 silver badge2 bronze badges 2- 1 See stackoverflow.com/questions/133925/… – Mohammed H Commented Dec 3, 2012 at 6:47
- 1 Please check this question stackoverflow.com/questions/8389646/… – Subodh Ghulaxe Commented Dec 3, 2012 at 6:48
4 Answers
Reset to default 8Not 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();
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.
You can put the id in a form, use document.forms["myform"].submit();
and returns a redirect action in your request handler on server.
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.