jquery solutions to post to another site from static html page

ぃ、小莉子 提交于 2020-01-13 11:05:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!