5
Ciao Ho un chiamata AJAX:server ha risposto con uno stato di 500 (Internal Server Error) quando si utilizza Ajax
$.ajax({
url: "/Orders/CheckIfExists",
type: "GET",
contentType: "application/json; charset=utf-8",
data: {
catalogNumber: viewModel.catalogNumber,
quantity: viewModel.quantity
},
error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},
success: function (data) {
if(data.ok)
{
alert(data.quantity)
}
}
})
});
ed ecco il metodo di controllo:
public JsonResult CheckIfExists(string catalogNumber, int quantity)
{
List<Expression<Func<DeviceInstance, bool>>> where = new List<Expression<Func<DeviceInstance, bool>>>();
where.Add(w=>w.DeviceUsage.UserId==1);
where.Add(w => w.Project == null);
where.Add(w => w.Device.CatalogNo == catalogNumber);
var result = unitOfWork.deviceInstanceRepository.Get(where)
.GroupBy(w => new
{
DeviceId = w.DeviceId,
CatalogName = w.Device.CatalogNo,
})
.Select(s => new
{
Quantity = s.Sum(x => x.Quantity),
}).First();
if (result.Quantity >= quantity)
{
return Json(new { ok = true, quantity = result.Quantity});
}
return Json(new { ok = false });
}
Ma sto ottenendo sempre Errore interno 500. I dati sono ricevuti con il metodo e tutti i calcoli sono ok. Compongo restituire JSON come nell'esempio. Dove ho fatto un errore?
Grazie uomo !!! ... Ti amo –