views:

321

answers:

2

Need to post data from a static html page to another page which is hosted on another domain. Normally I'd create and iframe with a form inside of it with a post method, and whose actions is directed to that web page, and finally submit that form. The complexity is I'd collect data from my static html page and create a similar (replica) form inside the iframe (with the above attributes viz method & action mainly); if there are a lot of fields I'd struggle to do it via javascript alone. So are there any jquery solutions for just this thing?

+1  A: 

Can you not post directly to the external URL? Youll run into more issues/complexity if you try to do it through js as then youre going to have to use a proxy to actually end the data.

prodigitalson
what if I need to be redirected to another static page (hosted on the same server) after the posting to the other site (diff server)? PS: I haven't designed that ext site either...
deostroll
In that case if there isnt soem supplied "callback url" feature on the remote app youll have to proxy it anyhow - submitting to your porxy script locally then build a post request for the external page and then rendering your own page upon success/failure. This is the same essentially with or without js really and ideally your going to do this serverside with some kind of dynamic language so you can make use of cURL or something similar. I suppose you could accomplish it with an invisible iframe but if youve got php/perl/python available that would be much easier i would think.
prodigitalson
A: 

You could try using JSONP as an alternative method. A quick overview of JSONP can be found on wikipedia (http://en.wikipedia.org/wiki/JSON#JSONP). jQuery implements JSONP support through the .getJSON method (http://docs.jquery.com/Ajax/jQuery.getJSON).

Unfortunately, to use JSONP you need to submit the form data as a query string (GET request, instead of a POST request). You can serialize a form into a query string using jquery's serialize method (http://docs.jquery.com/Ajax/serialize).

smaglio81