Instead of jquery $ .post forms a cross-domain data submitted N

Source: http: //blog.csdn.net/china_skag/article/details/7410918

N forms a cross-domain:

1. Cross-domain submitted directly in jquery $ .getJSON

          Advantages: The return value can be directly cross-domain;

          Disadvantage: the small amount of data ;

          Submission: only get (no $ .postJSON)

[javascript]  view plain copy
  1.  $.getJSON("http://www.sendnet.cn/?callback=?" , { UserId: 1001 },  
  2. nction (data) {  
  3. alert(data.info);  
  4. ;  
[javascript]  view plain copy
  1. $.ajax({  
  2.              type: "Get",  
  3.              url: "http://www.sendnet.cn/?UserId=1001",  
  4.              cache: false,  
  5.              error: function () { },  
  6.              jsonp: "callback",  
  7.              dataType: "jsonp",  
  8.              success: function (result) {  
  9.                  alert(result.info);   
  10.              }  
  11.          });  



 

2. iframe is embedded in a page, the iframe to the width and height across domains submitted 0

           Advantage: Direct cross-domain;

           Disadvantages: None Return Value ( departing from the essence ajax );

          Submission: get / post

[plain]  view plain copy
  1. Using a hidden iframe to submit the form   
  2. 1, an iframe is embedded in the page, the iframe width and height is set to 0   
  3. 2. Set a from the inside of the iframe in form, the form is the real contents of the form to be submitted.   
  4. 3. When the button is clicked when the iframe is in the form submission.  
  5.   
  6.   
  7. <form id="form2" name="form2" method="post" action="a,jsp" enctype="multipart/form-data">   
  8.   <input name="option_13412" id="option_13412" type="text"/>   
  9.   <input name="option_13413" id="option_13413" type="text"/>   
  10.   <input name="option_13414" id="option_13414" type="text"/>   
  11.   <input name="option_13415" id="option_13415" type="text"/>   
  12. </form>  
  13.   
  14. 使用jquery来啊操作iframe中的表单元素   
  15. $(window.frames["iframe1"].document).find("#option_13412").val(name);   
  16. $(window.frames["iframe1"].document).find("#option_13413").val(phone);   
  17. $(window.frames["iframe1"].document).find("#option_13415").val(content);  
  18.   
  19. 通过按钮来提交iframe里的表单   
  20. $(window.frames["iframe1"].document).find("#form2").submit();  



 

3.直接用$.post跨域,先提交到本地域名下一个代理程序,通过代理程序向目的域名进行post或get提交,并根据目的域名的返回值通过代理 程序返回给本地页面

          优点:有返回值,可直接跨域,可通过 代理程序 统计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 ............

 

Published 24 original articles · won praise 3 · views 40000 +

Guess you like

Origin blog.csdn.net/u012787757/article/details/25985589