Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  87] [ 3]  / answers: 1 / hits: 15456  / 10 Years ago, thu, july 31, 2014, 12:00:00
<script>
$.getJSON('url', function (data) {
console.log(Before:+data);
t = data;
console.log(After:+t);
});
</script>


When I am using getJson method to get data from REST API , I am getting the error:




Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at the url. This can be fixed by moving the resource to the same domain or enabling CORS.




How do I solve this? Please help.


More From » jquery

 Answers
28

Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at the url. This can be fixed by moving the
resource to the same domain or enabling CORS.




It means you should have api (url in your code) and the file which has your script must be in same domain



Or



Add the Access-Control-Allow-Origin header in the API(url in your code) domain



<FilesMatch .(php)$>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin *
</IfModule>
</FilesMatch>


* to allow all cross domainrequests


[#69986] Monday, July 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyterryp

Total Points: 290
Total Questions: 92
Total Answers: 95

Location: Montenegro
Member since Sun, May 7, 2023
1 Year ago
;