I'm new to APS.NET MVC WEB API programming.
So here is my problem, I have Created an ASP.NET WEB API project with the following Code
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<Employee> Get()
{
return new List<Employee>()
{
new Employee(){ EmpId=1,EmpName="xyz" },
new Employee(){EmpId=2,EmpName="abc"}
};
}
// GET api/values/5
public Employee Get(int id)
{
return new Employee() { EmpId = id, EmpName = "xyz" };
}
}
simple right..!!
the next thing i did is created an html file and write an ajax method to get data from web api
$(function () {
var obj = {};
$.ajax({
type: "GET",
url: "http://localhost:2797/api/values/1",
data: JSON.stringify(obj),
dataType: "JSON",
contentType: "application/json; charset=UTF-8",
success: function (data) {
alert(data.EmpName);
},
failure: function (data) {
alert("Error Occured");
}
});
});
now here is the problem my jquery script is able to contact to webapi because the breakpoints breaks when ever the html page get Refreshed and it also returns the value but for some unknown reason the alert message in Success function wont hit. and i don't know why
Please Help
Thanks in Advance..!!