Skip to content
Advertisement

CORS not working php

I am trying to post form data from www.siteone.com to www.sitetwo.com via CORS. My ajax code is this:

JavaScript

and the file cors.php in www.sitetwo.com is as follows:

JavaScript

But still Access-control-Allow-Origin error is thrown. The error thrown is this:

JavaScript

I came to know that, using CORS by just allowing the remote website via headers, we can use cross-domain request. But when I tried like this, error is thrown. Have I missed anything in here? Here is my request/response headers:

JavaScript

Advertisement

Answer

Finally, I myself have solved the problem explained in the question. The code that I have implemented for accessing header is incorrect.

The below mentioned two line code, when given, didn’t work:

JavaScript

But handling CORS requests properly is a tad more involved. Here is a function that will respond more fully. The updated code is this :

JavaScript

I have found from another post It worked….

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement