最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to solve Cross-Origin Request Blocked error in firefox - Stack Overflow

programmeradmin2浏览0评论
<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.

<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.

Share Improve this question edited Jul 31, 2014 at 6:03 Phil 165k25 gold badges262 silver badges267 bronze badges asked Jul 31, 2014 at 5:59 user2806784user2806784 251 gold badge2 silver badges4 bronze badges 8
  • 1 "by moving the resource to the same domain or enabling CORS" or, if the service supports jsonp, using jsonp. – Kevin B Commented Jul 31, 2014 at 6:00
  • 1 What it means moving the resource to same domain or how to enable CORS ? – user2806784 Commented Jul 31, 2014 at 6:01
  • it means exactly what that text says... i'm not sure how to put it simpler. Move your service (the resource) to the same domain (your webserver) or enable CORS (which is a process in which a cross origin request is made. research it.) – Kevin B Commented Jul 31, 2014 at 6:02
  • This question appears to be off-topic because the answer is provided by the error message – Phil Commented Jul 31, 2014 at 6:02
  • 1 yes answer is provided. if u can explain what it means. – user2806784 Commented Jul 31, 2014 at 6:03
 |  Show 3 more ments

2 Answers 2

Reset to default 3

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

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

I added this to my httpd-vhosts.conf and the error was solved

发布评论

评论列表(0)

  1. 暂无评论