Source: http: //blog.csdn.net/china_skag/article/details/7410918
N forms a cross-domain:
1. Cross-domain submitted directly in jquery $ .getJSONAdvantages: The return value can be directly cross-domain;
Disadvantage: the small amount of data ;
Submission: only get (no $ .postJSON)
- $.getJSON("http://www.sendnet.cn/?callback=?" , { UserId: 1001 },
- nction (data) {
- alert(data.info);
- ;
- $.ajax({
- type: "Get",
- url: "http://www.sendnet.cn/?UserId=1001",
- cache: false,
- error: function () { },
- jsonp: "callback",
- dataType: "jsonp",
- success: function (result) {
- alert(result.info);
- }
- });
Advantage: Direct cross-domain;
Disadvantages: None Return Value ( departing from the essence ajax );
Submission: get / post
- Using a hidden iframe to submit the form
- 1, an iframe is embedded in the page, the iframe width and height is set to 0
- 2. Set a from the inside of the iframe in form, the form is the real contents of the form to be submitted.
- 3. When the button is clicked when the iframe is in the form submission.
- <form id="form2" name="form2" method="post" action="a,jsp" enctype="multipart/form-data">
- <input name="option_13412" id="option_13412" type="text"/>
- <input name="option_13413" id="option_13413" type="text"/>
- <input name="option_13414" id="option_13414" type="text"/>
- <input name="option_13415" id="option_13415" type="text"/>
- </form>
- 使用jquery来啊操作iframe中的表单元素
- $(window.frames["iframe1"].document).find("#option_13412").val(name);
- $(window.frames["iframe1"].document).find("#option_13413").val(phone);
- $(window.frames["iframe1"].document).find("#option_13415").val(content);
- 通过按钮来提交iframe里的表单
- $(window.frames["iframe1"].document).find("#form2").submit();
优点:有返回值,可直接跨域,可通过 代理程序 统计ip等用户信息,增加安全性;
Submission: get / post
Complexity: engineer needs a front end and a rear end fitting Engineers (php / java ../ Engineers)
Disadvantages: need to consume local server resources, increase ajax waiting time (negligible)
4. The idea of Baidu to learn: Due call any js file does not involve cross-domain problem, so you can call js files on a remote server to write js script, the file you need to achieve business.
That a.js dynamic invocation www.baidu.com/b.js, which b.js achieve business
5. to be studied ............