When using window.location.href, I'd like to pass POST data to the new page I'm opening. is this possible using JavaScript and jQuery?
+4
A:
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.
Guffa
2010-03-03 00:41:29
I have data coming from 3 different forms and I am trying to send all 3 forms to the same page so I've been trying to serialize the forms with jQuery and send them some other way
Brian
2010-03-03 01:55:20
@Brian: Can't you just put everything in one `form`, so everything is sent together automatically?
Marcel Korpel
2010-03-03 02:26:39
One form is in a jQueryUI dialog box - so I can't just include them all.
Brian
2010-03-03 02:42:21
Pull out all their values, _dynamically_ build a form with all of the fields in all three forms, and submit that form. The form can be invisible. Don't use a JQuery AJAX method, use `$("#myForm").submit()`. The form- which will be invisible, and only used to submit values from your client side code, not user input- will never be shown nor otherwise used, and the page will be refreshed.
Matt Luongo
2010-03-03 05:36:41