问题
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:
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).
来源:https://stackoverflow.com/questions/2102268/jquery-solutions-to-post-to-another-site-from-static-html-page