n Forms of cross-domain commit data instead of jquery $.post

Source: Internet
Author: User

n Forms of cross-domain:

1. Cross-domain submission directly with $.getjson in jquery

Advantages: There are return values, can be directly across the domain;

Disadvantage: small amount of data ;

How to submit: Get only (no $.postjson)

    $.getjson ("http://www.sendnet.cn/?callback=", {userid:1001},function (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);                  }             });

2. Embed an IFRAME in the page, set the width and height of the iframe to 0 for cross-domain submissions

Advantages: Can be directly across the domain;

Cons: no return value ( out of Ajax nature );

Submission Method: Get/post

Use a hidden iframe to submit Form 1, embed an IFRAME in the page, and set the width and height of the iframe to 0 2. In the IFRAME, set up a from form, and the content of the form is the form content that is really being submitted. 3. When the button is clicked, the form in the IFRAME is submitted. <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> use jquery to manipulate form elements in an 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), submit the form in the IFRAME via the button $ (window.frames[" Iframe1 "].document). Find (" #form2 "). Submit ();

3. Directly with $.post cross-domain, first submitted to the local domain name of the next agent, through the agent to the destination domain name for post or get submission, and based on the return value of the destination domain name through the agent returned to the local page

Advantages: There are return values, can be directly across the domain, through the agent to statistics IP and other user information, increase security;

Submission Method: Get/post

Complexity: Requires front-end engineers and back-end engineers to work together (Php/java. Engineers

Disadvantage: Need to consume local server resources, increase Ajax wait time (can be ignored)

4. The idea of learning from Baidu: Because calling any JS file does not involve cross-domain issues, so the JS script can be written to invoke the JS file on the remote server, the file to achieve the business you need.

That is, a.js dynamically calls Www.baidu.com/b.js, where B.js implements the business


5. Pending research ......

n Forms of cross-domain commit data instead of jquery $.post

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.