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

An in-depth analysis of Nginx's implementation of AJAX cross-domain requests

亚连
Release: 2018-05-23 17:11:34
Original
1926 people have browsed it

AJAX requests from one domain to another domain will have cross-domain problems. So how to implement ajax cross-domain request on nginx? This problem stumps many friends. Below I will bring you relevant knowledge about Nginx’s implementation of AJAX cross-domain request issues. Friends who are interested can learn together.

AJAX requests from one domain to another domain will have cross-domain issues. The problem. So how to implement ajax cross-domain request on nginx? To enable cross-domain requests on nginx, add_header Access-Control* directives need to be added. As shown below:

location /{
add_header 'Access-Control-Allow-Origin' 'http://other.subdomain.com';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET';
...
...
the rest of your configuration here
...
...
}
Copy after login

Comments are as follows:

First instruction: Authorize requests from other.subdomain.com

Second instruction: When this flag is true When responding to the request, whether it can be exposed

Third day instructions: Specify the request method, which can be GET, POST, etc.

If you need to allow access from any domain, you can configure it like this :

Access-Control-Allow-Origin: *

Restart nginx

service nginx reload

ajax cross-domain request test

When successful, the response header is as follows:

HTTP/1.1 200 OK
Server: nginx
Access-Control-Allow-Origin: other.subdomain.com
Copy after login

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

Related articles:

How to use the Rating control of AjaxToolKit

Implementing file upload with progress bar based on Ajax technology

Discuss issues related to readyState and status in Ajax

The above is the detailed content of An in-depth analysis of Nginx's implementation of AJAX cross-domain requests. 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 admin@php.cn
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!