Home  >  Article  >  Backend Development  >  How to deal with this kind of failure during ajax submission?

How to deal with this kind of failure during ajax submission?

WBOY
WBOYOriginal
2016-08-04 09:22:031266browse

I have added header("Access-Control-Allow-Origin:*");
but still returns error message:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:10860' is therefore not allowed access.

Translation:
Failed access control check against preflight request: No access control allowed origin is present on the requested resource. HTTP://127.0.0.1:10860 origin" therefore access is not allowed.

How to deal with this error

Reply content:

I have added header("Access-Control-Allow-Origin:*");
but still returns error message:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:10860' is therefore not allowed access.

Translation:
Failed access control check against preflight request: No access control allowed origin is present on the requested resource. HTTP://127.0.0.1:10860 origin" therefore access is not allowed.

How to deal with this error

Chrome’s error report is quite funny

As long as it is a cross-domain request and the return value is greater than or equal to 400, this error (warning?) will be reported.

Check specifically to see if the request returns a value. (Switch to the network bar in chrome)

The request is cross-domain
Requests for communication between different ports of the same domain name are also considered cross-domain. They are protected by the browser's same-origin policy and the request is interrupted.
For specific solutions, please see this blog
http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html#m0

If you capture some requests, you will find that there is an option request before the post request. You can check the information preflight request

It feels like the return header of the response is not added, Access-Control-Allow-Origin. Can you check the console to see the return header of this request? See if there is this field in the return header.

This error is a cross-domain error.

Statement:
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