Cross-domain $http request AngularJS

后端 未结 2 1321
粉色の甜心
粉色の甜心 2020-12-06 17:40

I have simple website I\'m building with AngularJS which calls an API for json data.

However I am getting Cross domain origin problem is there anyway around this to

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 17:48

    Install Fiddler. Add a custom rule to it:

    static function OnBeforeResponse(oSession: Session)
    {
        oSession.oResponse.headers.Add("Access-Control-Allow-Origin", "*");
    }
    

    This would allow you to make cross domain requests from localhost. If the API is HTTPS make sure you enable 'decrypt HTTPS traffic' in fiddler.

    Reference

    -------------------- UPDATE

    The response you are getting is JSON. Specifying JSONP as datatype would not work. When you do specify JSONP the return should be a function not JSON object.

    JSONP

提交回复
热议问题