Riccarr
Riccarr

Reputation: 111

Not getting callback from AngularJS $http.post

I'm not getting any callback to the success/fail handlers on my Angular $http.post call. My server side is .NET MVC controller; the controller is getting the file and works properly there, I've debugged through it, so the POST call itself seems to be working fine. There just isn't a callback on the client javascript side.

I've a basic scope function ...

$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);
        });
};

Neither of the alerts are popping up.

Server side controller is ...

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);
        }

The file is getting uploaded and stored in the "Upload_Data" folder.

Why no callback on the client side?

Upvotes: 1

Views: 55

Answers (1)

afrikaan
afrikaan

Reputation: 425

in scope you're calling result.status but your parameter name is response .Fix the name and try maybe there is a syntax error.

Upvotes: 1

Related Questions