【问题标题】:angular.js jsonp error status 404angular.js jsonp错误状态404
【发布时间】:2015-03-11 20:33:10
【问题描述】:

我有一个 SPA,我正在尝试使用角度 $http.jsonp 从远程 .NET WebAPI 获取 JSON 数据

var widgetApp = angular.module('widgetApp', ['ngRoute']).config(function($interpolateProvider){
    $interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});

widgetApp.controller('topStreaksCtrl', function ($scope, $http) {

  $http.jsonp('http://REMOTESERVER.azurewebsites.net/api/Serie/getdata?callback=JSON_CALLBACK')
     .success(function(response){
        $scope.data = response;
    }).
    error(function(data, status, headers, config){
        console.log(data);
        console.log(status);
        console.log(headers);
        console.log(config);
    })
});
angular.bootstrap(document, ['widgetApp']);

我可以在 Chrome 网络上看到响应数据,但 jsonp 函数总是返回错误。状态 404 ? WebAPI 上需要任何配置吗?

【问题讨论】:

  • 你能做到吗?

标签: .net angularjs azure asp.net-web-api jsonp


【解决方案1】:

如果您尝试从 Azure 提供静态数据,则需要将以下内容添加到您的 Web.config,否则您将收到 404,因为默认情况下未设置 json MIME 类型

Reference

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" />
     </staticContent>
    </system.webServer>
</configuration> 

【讨论】:

    猜你喜欢
    • 2016-12-22
    • 1970-01-01
    • 2018-11-18
    • 2013-02-18
    • 2014-12-09
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多