weixin_33749242 2014-11-12 18:02 采纳率: 0%
浏览 146

在Firefox中启用Cors

In angular js , i have write down the following code to call a api .

    $http({
        method: 'GET',
        url: 'https://www.example.com/api/v1/page',
        params: 'limit=10, sort_by=created:desc',
        //headers: {'Content-Type': 'application/json'}
        header:{'Access-Control-Allow-Origin': '*'}
    }).success(function(data){
        alert(data);
    }).error(function(){
        alert("2 error");
    });

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "url"

  • 写回答

1条回答 默认 最新

  • Didn"t forge 2014-11-12 18:09
    关注

    It is totally up to a server whether it supports CORS or not. You cannot do this from a requesting browser. It is the server that decides whether it wants to serve cross-origin requests or not.

    So, if a server is not configured to allow cross-origin requests, then a browser cannot change that.

    Another method of making cross origin requests is JSONP, but again the server must specifically support JSONP requests for them to work.

    If you have your own server, then you can make a request of your own server to act as a proxy to obtain the request from the other server and then give it back to you. Server to server requests are not limited by cross-origin (that is a browser thing only). This is less efficient, but is sometimes the only work-around if the original server does not support any cross origin access and cannot be changed to support it.

    If you are using an api that is intended to be used from other web sites, then it likely does support some sort of cross origin access and you should find out how that is intended to work from whatever documentation exists for that api. If you are using an api that is not intended to be used form other web sites, then you're out of luck unless you code your own server proxy that is served from the same server that hosts your web page. This is done this way by design so it is not easy to use someone else's API in your web site if they didn't specifically permit this type of cross origin access.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器