I'm trying to replace my $.ajax call with $http.get(). I get a 404 Not Found error when I try.
Here is the ajax call:
// ToDo: See if there is an $http.get equivalent. That way the callback doesn't have
// to be wrapped in $scope.apply().
$.ajax({
url: '/PrestoWeb/api/ping/responses/',
type: 'POST',
data: JSON.stringify(latestPingRequest),
contentType: "application/json",
success: function (responses) {
// do stuff
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
And this is the $http call:
var config = {
url: '/PrestoWeb/api/ping/responses/',
method: 'POST',
data: JSON.stringify(latestPingRequest),
contentType: "application/json"
};
$http.get(config)
.then(function (response) {
// do stuff
}, function (response) {
alert(response);
});
The ajax call works. The http call does not. The URL, type, and data are the exact same in both calls. What am I missing?
$http.getwithmethod: postis contradicting, right?$http.post()and$http.get()are shortcut methods. The first argument should be a URL. You don't even need the config object, because Angular will do those things for you:$http.post(url, data);$http.post(url, data, config). Also the $http module automatically stringifies for you, so you don't need to be doing that yourself. edit yes as @SunilD. says, you likely just need$http.post(url, { some: 'data' })