Allow My API To Be Access Via AJAX
I have an API that fetches some date on the server. public function post_events() { header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POS
Solution 1:
The browser makes first a pre-flight options call to your api and this is what it triggers the error: Access-Control-Allow-Origin
. You can create an endpoint on your api that accepts all the OPTIONS request and you have also to set the headers there like on the post events:
header('Access-Control-Allow-Origin: *');
The Status Code that you also receive is 404 Not Found. That means that is not able to find an OPTIONS endpoint.
Post a Comment for "Allow My API To Be Access Via AJAX"