Calling Web API not working in AngularJS using $http service
When calling ASP.NET Web API service inside the solution, I encountered an issue that is 404 not found. Given that this issue persists, I tried adding a forward slash before the url in the Ajax call which works.
AngularJS
I also make sure that the WebApiConfig.Register method gets executed in Global.asax.cs.
Global.asax.cs
AngularJS
$http({
//url: "EmployeeRoute/GetAll", //404 error
url: "/EmployeeRoute/GetAll",
dataType: 'json',
method: 'POST',
data: GetAll,
headers: {
"Content-Type": "application/json"
}
}).then(function (resp) {
if (typeof resp.data === 'object') {
return resp.data;
} else {
return $q.reject(response.data);
}
}, function (err) {
return $q.reject(err.data);
});
Global.asax.cs
protected void Application_Start(object sender, EventArgs e) { GlobalConfiguration.Configure(WebApiConfig.Register); }
Comments
Post a Comment