Home > Web Front-end > JS Tutorial > body text

Ajax cross-domain (same basic domain name) form submission method

亚连
Release: 2018-05-25 10:52:57
Original
1364 people have browsed it

This article mainly introduces the method of ajax cross-domain (same basic domain name) form submission. The example analyzes the cross-domain form submission skills during the Ajax submission process. Friends in need can refer to the following

Examples of this article Describes the method of ajax cross-domain (same basic domain name) form submission. Share it with everyone for your reference. The details are as follows:

1. Add the following js statement to the page for ajax submission:

Copy after login

2. When submitting the ajax form, you can use a jquery form plug-in jquery.form. js

The usage syntax is as follows:

//fromPost为要收集数据的form表单的id  
$("#formPost").ajaxSubmit({ 
  url:"跨域的业务处理地址", 
  cache:false, 
  dataType:"html", 
  iframe:true, 
  success:function (data){ 
 //返回如果是json可以这样处理一下,xml格式需要做其它的处理
 eval("data="+data); 
   if(data.flag == 'OK'){ 
   }
});
Copy after login

3. The return value of cross-domain business processing must contain the following statements

Copy after login

4. The remaining return value can be json , xml format or other customized formats, as long as the client can parse the desired results

5. In this way, the return value after the cross-domain submission of the form can be obtained in the ajax submission page , after getting the return value, you can continue to do other processing

Instructions:

1. Basic domain name: the public part of two or more domain names, The public part must include at least the second-level domain name or the part above the second-level domain name

2.document.domain="basic domain name"; //This sentence is to make the domain names the same and lift cross-domain restrictions. For details, see: "Analysis of points to note when setting document.domain in js to achieve cross-domain implementation"

3. There are many other solutions to cross-domain submission, such as: "Detailed explanation of js same-origin policy"

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

AJAX submission form data example analysis

A brief discussion on Ajax and its advantages and disadvantages

Ajax method of reading properties resource file data

The above is the detailed content of Ajax cross-domain (same basic domain name) form submission method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!