所以基本上我是使用42matters.com APP Market API从Google Play商店获取应用程序详细信息或信息,一切工作正常,并且我得到了JSON响应,但是当我在周末假期后回到办公室时,奇怪的错误来了,什么也没有返回。

我已经使用$ .getJSON函数,如:

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));
        });

如前所述,这是返回数据,我能够相应地更改所有内容,但现在它无缘无故地给了我这个错误
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,但没有任何 react ,尝试更改apache的conf文件以在其中启用CORS,但是该服务不会因此而重启,所以我陷入了困境。

还有一件事,当我在浏览器中手动输入以上链接时,它确实提供了所需的结果。请帮我解决

最佳答案

CORS 在浏览器端被阻止,不允许 AJAX 从另一个域请求数据。您应该联系 42matters.com 团队为您打开 crossdomain.xml,例如 CORS jQuery AJAX requestCan someone post a well formed crossdomain.xml sample?

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

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

10-04 23:12
查看更多