使用 .getJSON 获取 Play 商店应用详细信息时出现跨域阻止请求 [CORS] 错误 [英] Getting Cross Origin Block Request [CORS] error when using .getJSON to get Play Store App Details

查看:35
本文介绍了使用 .getJSON 获取 Play 商店应用详细信息时出现跨域阻止请求 [CORS] 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我使用 42matters.com APP market API 从 google play 商店获取应用程序详细信息或信息,一切正常,我收到了 JSON 响应,但是当我周末假期后回到办公室时,这个相当奇怪的错误来了,没有返回任何东西.

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.

我使用过 $.getJSON 函数,例如:

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

我已经使用 PHP 启用了 CORS,但没有发生任何事情,尝试更改 apache 的 conf 文件以在此处启用 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

推荐答案

CORS 在浏览器端被阻止,不允许 AJAX 从另一个域请求数据.您应该联系 42matters.com 团队为您打开 crossdomain.xml,像这样 CORS jQuery AJAX 请求有人可以发布格式良好的 crossdomain.xml 示例吗?

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?

或者 AJAX 跨域的解决方法是 JSONP:jQuery AJAX 跨域 但是API 应该支持这种请求.

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

最后一点是不要使用AJAX从其他来源收集数据,如果是移动平台,它应该有原生的HTTP请求对象来做到这一点

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

这篇关于使用 .getJSON 获取 Play 商店应用详细信息时出现跨域阻止请求 [CORS] 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆