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

javascript - Getting Cross Origin Block Request [CORS] error when using .getJSON to get Play Store App Details - Stack Overflow

programmeradmin1浏览0评论

So basically i was using 42matters APP market API to get the app details or information from the google play store, everything was working fine and i was getting the JSON response back, but when i came back to office after weekend holidays, this rather strange error came and nothing was being returned.

I have used $.getJSON function like:

var packageID = 'com.whatsapp';
   $.getJSON('.json?p='+packageID+'&access_token=accesstoken1234')
.done(function(appDetails) {
            $('#logo').html(JSON.stringify(appDetails));
        });

As mentioned this was returning the data and i was able to change everything accordingly but now it is giving me this error for no reason at all

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at .json?p=com.whatsapp&access_token=accesstoken1234. This can be fixed by moving the resource to the same domain or enabling CORS

i have enabled the CORS using PHP, and nothing happended, tried to change the conf file of apache to enable CORS there but the service wont restart with this, so i am stuck.

One more thing, when i manually enter the above link in the browser, it does give the desired result. Please help me resolve it

So basically i was using 42matters.com APP market API to get the app details or information from the google play store, everything was working fine and i was getting the JSON response back, but when i came back to office after weekend holidays, this rather strange error came and nothing was being returned.

I have used $.getJSON function like:

var packageID = 'com.whatsapp';
   $.getJSON('https://42matters.com/api/1/apps/lookup.json?p='+packageID+'&access_token=accesstoken1234')
.done(function(appDetails) {
            $('#logo').html(JSON.stringify(appDetails));
        });

As mentioned this was returning the data and i was able to change everything accordingly but now it is giving me this error for no reason at all

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://42matters.com/api/1/apps/lookup.json?p=com.whatsapp&access_token=accesstoken1234. This can be fixed by moving the resource to the same domain or enabling CORS

i have enabled the CORS using PHP, and nothing happended, tried to change the conf file of apache to enable CORS there but the service wont restart with this, so i am stuck.

One more thing, when i manually enter the above link in the browser, it does give the desired result. Please help me resolve it

Share Improve this question edited Apr 14, 2014 at 6:51 Hunain Usman asked Apr 14, 2014 at 6:29 Hunain UsmanHunain Usman 2,2285 gold badges24 silver badges32 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

CORS is blocked in browser side that won't allow AJAX to request data from another domain. You should contact the 42matters.com team to open the crossdomain.xml for you like this CORS jQuery AJAX request or Can someone post a well formed crossdomain.xml sample?

Or the workaround for AJAX Cross-Domain is JSONP: jQuery AJAX cross domain but the API should support this kind of request.

The last thing is don't use AJAX to collect data from another sources, if it is mobile platform, it should have native HTTP Request object to do this

I know it's old technology, but some of us still have to deal with this.

If you're dealing with an IIS6 web server:

  • Open Internet Information Service (IIS) Manager
  • Right click the site you want to enable CORS for and go to Properties
  • Change to the HTTP Headers tab
  • In the Custom HTTP headers section, click Add
  • Enter Access-Control-Allow-Origin as the header name
  • Enter * as the header value
  • Click Ok twice

IIS7 – Add this to your web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>
</configuration>

We can fix the problem by placing base tag on our html file.

<head>
<base href="http://www.otherdomain.com/xyz/">
</head>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论