小编Coo*_*SyS的帖子

Angular $ http错误响应statusText始终未定义

我试图向用户返回一个自定义错误消息,让他们知道出现错误时出了什么问题,但我已经尝试了所有内容来显示消息,似乎没有任何东西正在捕获它.这是我的角度代码:

$scope.save = function (style) {
    styleAPIservice.addStyle(style).success(function () {
        $scope.success = "Style added successfully";
    }).error(function (data, status, headers, config, statusText) {
        $scope.error = "An error occurred while saving style: " + data + "|"+data.data+"|"+data.statusText+"|"+statusText;
    });
}
Run Code Online (Sandbox Code Playgroud)

这是它调用的styleAPIservice函数:

styleAPI.addStyle = function (style) {
    return $http.post(AppRoot + "api/StyleAPI/",
        JSON.stringify(style),
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            });
}
Run Code Online (Sandbox Code Playgroud)

这是API函数:

[HttpPost]
public HttpResponseMessage PostStyle(Style style)
{
    if (string.IsNullOrEmpty(style.Pattern.PatternName) || string.IsNullOrEmpty(style.StockNumber))
        return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Pattern Name and Stock Number are required.");

    var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4 angularjs

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

asp.net-mvc-4 ×1

c# ×1