Ajax Cross-domain (the underlying domain name is the same) Form submission method _ajax related

Source: Internet
Author: User

The examples in this article describe the Ajax Cross-domain (same base domain name) Form submission method. Share to everyone for your reference. Specifically as follows:

1. Add the following JS statement to the page that makes the AJAX submission:

<script type= "Text/javascript" > 
  document.domain= "basic domain name"; 
</script> 

2.ajax form when submitting a form, you can use a single form plug-in for jquery Jquery.form.js

Use syntax as follows:

Frompost is the ID $ ("#formPost") for form forms for which you want to collect data  
. Ajaxsubmit ({ 
  URL: "Business processing addresses across domains", 
  cache:false, 
  dataType: "HTML", 
  iframe:true, 
  success:function (data) { 
 //returns if JSON can do this, the XML format needs to do other processing
 eval ("Data=" +data); 
   if (Data.flag = = ' OK ') { 
   }
});

3. The return value of a cross-domain business process must contain the following statement

<script type= "Text/javascript" >
  document.domain= "basic domain name";
</script>

4. The remaining return value can be json,xml format or other custom format, as long as the client can parse out the desired result

5. So in the AJAX submission of the page can be taken to form a cross-domain submission after the return value, take the return value can be followed by other processing

Description

1. Basic domain name: Two and more than two domain name public part, the public part must contain at least two level domain name or two level domain name above part

2.document.domain= "Basic domain Name"; This sentence is to make the domain name the same, to remove the restrictions on Cross-domain, see: "JS set Document.domain to achieve cross-domain attention point analysis"

3. There are many other solutions to cross domain submissions, such as: "JS homology strategy"

I hope this article will help you with your JavaScript programming.

Related Article

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.