jquery解决方案从静态html页面发布到另一个网站 [英] jquery solutions to post to another site from static html page
问题描述
需要将数据从静态html页面发布到托管在另一个域上的另一个页面。通常我会用post方法创建一个带有表单的iframe,并将其操作指向该网页,最后提交该表单。复杂的是,我会从我的静态html页面收集数据,并在iframe中创建一个类似的(副本)表单(主要使用上述属性即方法和操作);如果有很多领域,我会努力通过javascript独自完成。那么是否有任何jquery解决方案只是为了这件事?解析方案
您可以尝试使用JSONP作为替代方法。 JSONP快速浏览可以在wikipedia上找到( http://en.wikipedia.org/wiki / JSON#JSONP )。 jQuery通过.getJSON方法实现JSONP支持( http://docs.jquery.com/Ajax/ jQuery.getJSON )。
不幸的是,要使用JSONP,你需要提交表单数据作为查询字符串(GET请求,而不是POST请求) 。您可以使用jquery的序列化方法将表单序列化为查询字符串( http://docs.jquery.com/ Ajax / serialize )。
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?
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).
这篇关于jquery解决方案从静态html页面发布到另一个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!