o..o
o..o

Reputation: 1921

Angular $http is not sending data

I know it has been solved here many times, but I'm still not able to get it working.

My js call is:

var data = { value: 7 };
$http.post('api/controller/method', data);

But in fiddler there is no Content-Type and no JSON data. I want the Content-Type to be 'application/json' which should be default, right?

Thanks

Upvotes: 1

Views: 96

Answers (2)

Raghav Patel
Raghav Patel

Reputation: 843

Try this:

var response = $http.post('api/controller/method', data);
response.success(function(data, status1, headers, config) {
    //
}

Upvotes: 0

Rodrigo Garcia
Rodrigo Garcia

Reputation: 58

var data = { value: 7 };
$http({
        url: "api/controller/method",
            method: "POST",
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data: $.param(data)
        }).success(function(data, status, headers, config) {
            //some code when success post
            }).error(function(data, status, headers, config) {
            //some code when error post
        });

Upvotes: 1

Related Questions