Ajax Angularjs和Web Api-JSON格式问题

Ajax Angularjs和Web Api-JSON格式问题,ajax,json,angularjs,asp.net-web-api,asp.net-web-api2,Ajax,Json,Angularjs,Asp.net Web Api,Asp.net Web Api2,我有一个轻量级的Angularjs应用程序,我正在尝试从我的ASP.NET Web Api控制器处理json 在angularjs工厂: adapter.getLegacyCouriers = function(id) { return $http({ method: 'GET', url: 'http://legacywebapi.azurewebsites.net/api/legacycourier' }); } 在控制器中: legacyService.getL

我有一个轻量级的Angularjs应用程序,我正在尝试从我的ASP.NET Web Api控制器处理json

在angularjs工厂:

adapter.getLegacyCouriers = function(id) {
  return $http({
    method: 'GET', 
    url: 'http://legacywebapi.azurewebsites.net/api/legacycourier'
  });
}
在控制器中:

legacyService.getLegacyCouriers()
.success(function (response) {
       alert("Success: " + JSON.stringify(response));
})
.error(function (response) { 
    alert("Error: " + JSON.stringify(response)); 
});
当我在$http get中交换URL时,它会点击success块。但是,返回json格式的默认URL会命中错误块


有人能帮我吗?两者都返回应用程序/json响应头,并且都返回200 OK的状态(使用Chrome进行调试)。我不明白我的json为什么会出现错误块。

您的服务将使用

请求的服务器上不存在“Access Control Allow Origin”标头 资源。来源“run.jsbin.com”;因此不允许访问。 从您的legacywebapi.azurewebsites.net/api/legacycourier

请看这里


只需启用跨源资源共享。

@mm确认此消息对应成功的示例request@rnrneverdies在测试geonames api时,我没有收到“每日限制”消息。它返回的是一个实际的json结果集,其格式与我从Web Api控制器返回的结果集完全相同(或者我相信是这样),看起来像是参数问题。很可能该方法没有默认参数。服务器端发生了一些事情。尝试在日志中记录任何异常api@Fals正如您通过测试URL所看到的,没有服务器端错误:-它以200 OK响应,并且应用程序/json头i've-get-response请求的资源上没有“Access-Control-Allow-Origin”头。因此,不允许访问源“”。请看这里