Это мой код jquery ajax, который я использую для вызова действия веб-API.
var baseurl = 'http://localhost:58782/api/Appointments/UserAppointments/tridip@gmail.com/'
$.ajax({
url: baseurl,
type: 'GET',
dataType: 'json',
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log(textStatus);
}
}).done(function () {
});
Это мой код веб-API, который возвращает IEnumerable<Entities.UserAppointments>
на System.Net.Http.HttpResponseMessage
Полныйкод веб-API.Проверено и работает.Я предполагаю, что ошибка в коде jquery ajax.
[System.Web.Http.HttpGet, System.Web.Http.Route("UserAppointments/{email}")]
public System.Net.Http.HttpResponseMessage UserAppointments(string email = null)
{
System.Net.Http.HttpResponseMessage retObject = null;
if (!string.IsNullOrEmpty(email))
{
UserAppointmentService _appservice = new UserAppointmentService();
IEnumerable<Entities.UserAppointments> app = _appservice.GetAllUserAppointments(email);
if (app.Count() <= 0)
{
var message = string.Format("No appointment found for the user [{0}]", email);
HttpError err = new HttpError(message);
retObject = Request.CreateErrorResponse(System.Net.HttpStatusCode.NotFound, err);
retObject.ReasonPhrase = message;
}
else
{
retObject = Request.CreateResponse(System.Net.HttpStatusCode.OK, app);
}
}
else
{
var message = string.Format("No email provided");
HttpError err = new HttpError(message);
retObject = Request.CreateErrorResponse(System.Net.HttpStatusCode.NotFound, err);
retObject.ReasonPhrase = message;
}
return retObject;
}
public class UserAppointments
{
public int ID { get; set; }
public string DoctorName { get; set; }
public string AvailableDate { get; set; }
public string AvailableTime { get; set; }
public string Email { get; set; }
}
Моя цель - захватить IEnumerable<Entities.UserAppointments>
с помощью jquery, выполнить итерацию в данных и динамически добавить эти данные в таблицу.
Пожалуйста, укажите мнекак это сделать.спасибо