【问题标题】:Not getting callback from AngularJS $http.post没有从 AngularJS $http.post 得到回调
【发布时间】:2016-11-22 21:50:27
【问题描述】:

在我的 Angular $http.post 调用中,我没有收到任何对成功/失败处理程序的回调。 我的服务器端是.NET MVC 控制器;控制器正在获取文件并在那里正常工作,我已经调试过了,所以 POST 调用本身似乎工作正常。客户端javascript端没有回调。

我有一个基本的作用域函数...

$scope.uploadFile = function(files) {
    var fd = new FormData();
    fd.append("file", files[0]);

    $http.post('api/clubs/upload', fd, {
        withCredentials: true,
        headers: {'Content-Type': undefined },
        transformRequest: angular.identity
    })
        .then(function (response) {
            alert("Success:" + result.status);
        }, function (response) {
            alert("Failuer: " + result.status);
        });
};

两个警报都没有弹出。

服务器端控制器是...

string root = HttpContext.Current.Server.MapPath("~/Upload_Data");
        var provider = new MultipartFormDataStreamProvider(root);

        try
        {
            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);

            // This illustrates how to get the file names.
            foreach (MultipartFileData file in provider.FileData)
            {
                Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                Trace.WriteLine("Server file path: " + file.LocalFileName);
            }


            // Show all the key-value pairs.
            foreach (var key in provider.FormData.AllKeys)
            {
                foreach (var val in provider.FormData.GetValues(key))
                {
                    Trace.WriteLine(string.Format("{0}: {1}", key, val));
                }
            }


            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (System.Exception e)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
        }

文件正在上传并存储在“Upload_Data”文件夹中。

为什么客户端没有回调?

【问题讨论】:

    标签: .net angularjs asp.net-mvc http-post


    【解决方案1】:

    在您调用result.status 的范围内,但您的参数名称是response。修复名称并尝试可能存在语法错误。

    【讨论】:

    • 哈!谢谢你的眼睛,kyur。那是(愚蠢的)问题。现在工作。
    猜你喜欢
    • 2017-09-20
    • 1970-01-01
    • 2015-05-15
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2013-06-06
    相关资源
    最近更新 更多