Getting the response as “data”:null,“status”:-1 when calling web api from AngularJS

前端 未结 1 1078
深忆病人
深忆病人 2021-01-26 08:53

I am trying to call Web API GET Method from Angular JS 1.6.0 and getting the following error:-

Possibly unhandled rejection: {\"data\":null,\"status\":-

相关标签:
1条回答
  • 2021-01-26 09:37

    You probably need to enable CORS:

    In your WebApiConfig.cs file, add this:

    var cors = new EnableCorsAttribute("*", "*", "*");
    config.EnableCors(cors);
    

    CORS is a check by the browser to enforce same origin policy when the call is made using scripting. You won't see it when using something like Fiddler or when accessing the api directly in the browser.

    0 讨论(0)
提交回复
热议问题