I have the following controller defined in a web api project
public IEnumerable<Speciality> GetAllSpecialities()
{
List<Speciality> specialities = null;
try
{
specialities = (new Datatable(Properties.Settings.Default.DataConnection)).Select<Speciality>(null);
}
catch ( System.Exception ex)
{
throw ex;
}
finally
{
}
return specialities;
}
public IHttpActionResult GetSpeciality(String id)
{
Speciality speciality = null;
try
{
speciality = DALObject.Get<Speciality>(Properties.Settings.Default.DataConnection,
new Dictionary<string, object>()
{
{ "SpecialityCode",id }
},null);
if (speciality == null)
{
return NotFound();
}
}
catch ( System.Exception ex)
{
throw ex;
}
return Ok(speciality);
}
If I call the web service from the browser they both return a JSON object back, the first a list of specialties and the second an individual one.
In my page I have the following ajax code
$.ajax({
url: 'http://stg1edmapps01:9090/api/specialties',
contentType:'json',
success: function (result) {
alert('data collected successfully');
},
error: function (request, status, error) {
alert('something is broken');
alert('Response ' + error);
}
});
Here I get three alerts;
The first is the one showing it calling the code The second says 'something is broken'
The third however just gives the word 'Response' unless that is I pass error to the final alert in which case it gives the string 'Response error'.
What have I done wrong in that I was expecting to get a JSON object with a list of specialties. The same happens regardless of passing api/specialties/100 or just api/specialties