Home Web Front-end JS Tutorial Ajax cross-domain (same basic domain name) form submission method

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

May 25, 2018 am 10:52 AM
ajax domain name

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:

<script type="text/javascript"> 
  document.domain="基础域名"; 
</script>
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 == &#39;OK&#39;){ 
   }
});
Copy after login

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

<script type="text/javascript">
  document.domain="基础域名";
</script>
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!

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 admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

PHP and Ajax: Building an autocomplete suggestion engine PHP and Ajax: Building an autocomplete suggestion engine Jun 02, 2024 pm 08:39 PM

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

What is the method to apply for a domestic permanent free domain name? What is the method to apply for a domestic permanent free domain name? Jan 19, 2024 pm 04:01 PM

Application method: 1. Apply for a free domain name through the Ministry of Industry and Information Technology website, and you can obtain the free domain name after waiting for approval; 2. Apply for a domain name for free through DNSPod. Users can register an account on DNSPod and apply for a free second-level domain name; 3. Choose a reliable domain name Free domain name service providers, choose a reliable provider through comparison and understanding; 4. Register an account, click the registration button, fill in the relevant personal information as required and create an account; 5. Search and select the domain name.

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

PHP domain name redirection example demonstration and effect display PHP domain name redirection example demonstration and effect display Mar 28, 2024 am 08:21 AM

PHP domain name redirection is one of the commonly used technologies in website development. Through domain name redirection, users can automatically jump to another URL when visiting one URL, thereby achieving website traffic guidance, brand promotion and other purposes. The following will use a specific example to demonstrate the implementation method of PHP domain name redirection and show the effect. Create a simple PHP file named redirect.php with the following code:

How to register a corporate email domain name How to register a corporate email domain name May 07, 2024 pm 01:48 PM

1. Choose an available domain name: The corporate email domain name should be related to the corporate brand or business. 2. Check whether the domain name has been registered: After selecting the corporate email domain name, you need to check whether the domain name has been registered by other companies. 3. Choose an email service provider: Enterprises can search for different email service providers through search engines and choose a provider based on their needs. 4. Create an account: The process of registering for an email service may be slightly different, but you usually need to fill in the basic information of the company and administrator and create an administrator account.

See all articles