how to bypass Access-Control-Allow-Origin?
Put this on top of retrieve.php:
header('Access-Control-Allow-Origin: *');
Note that this effectively disables CORS protection, and leaves your users exposed to attack. If you're not completely certain that you need to allow all origins, you should lock this down to a more specific origin:
header('Access-Control-Allow-Origin: https://www.example.com');
Please refer to following stack answer for better understanding of Access-Control-Allow-Origin
https://stackoverflow.com/a/10636765/413670
how to bypass Access-Control-Allow-Origin for an API post request
i have found solution ,
its not the right way , but it can be better than installing the browser plugin to pybass CORS ,
solution is use a proxy , something like this :
var proxy = 'https://cors-anywhere.herokuapp.com/';
var url = "api url";
// GET SESSION ID
$.ajax({
url: proxy + url,
How to bypass Cross origin policy
As already answered, you want a simple php proxy script.
This way your server grabs the json file and you simply access your server from client side. . That way javascript is only dealing with the same domain.
<?php
header('Content-Type: application/json');
echo file_get_contents('http://example.com/data.json');
?>
Proxy.php
<?php
header('Content-Type: application/json');
echo file_get_contents('http://example.com/'.$_REQUEST['file']);
?>
Another way also would be to send all of the request headers as a query string, this could be post/get as well
if (isset($_REQUEST['query'])) {
$sQuery = http_build_query($_REQUEST);
header('Content-Type: application/json');
echo file_get_contents('https://www.example.com?'.$sQuery);
exit;
}
?>
Using the second example you can try something like http://localhost/proxy.php?file=somefile.json
HTACCESS METHOD
Refer the following page about using a htaccess file on the server htaccess Access-Control-Allow-Origin
<FilesMatch ".(json|js|jsn)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
Related Topics
How to Apply CSS to Half of a Character
How to Simulate a Click by Using X,Y Coordinates in JavaScript
Event Detect When CSS Property Changed Using Jquery
How to Turn Off Antialiasing on an HTML ≪Canvas≫ Element
Html Script Tag: Type or Language (Or Omit Both)
Resize Html5 Canvas to Fit Window
Detect All Changes to a ≪Input Type="Text"≫ (Immediately) Using Jquery
Get Div Height With Plain JavaScript
Difference Between Val() and Text()
Adding Options to Select With JavaScript
Why Does Canvas.Todataurl() Throw a Security Exception
Using HTML Script Tags to Code While They Have a Source
How Does the Paste Image from Clipboard Functionality Work in Gmail and Google Chrome 12+
When Do Items in Html5 Local Storage Expire