Benim ajax çağrısı buSürekli MVC denetleyiciye jquery ajax yayında 400 (Bad Request) alıcı
$.ajax({ //actually approve or reject the promotion
url: url,
type: "POST",
data: '{'+data.PromotionId+','+data.UserId+','+data.ReasonText+'}',
dataType: "json",
//contentType: "application/json; charset=utf-8",
success: function (data) {
if (indicator == 'A') {
alert('Promotion approved successfully!');
}
else {
alert('Promotion rejected successfully.');
}
var homelink = '<%: Url.Action("Index","Home") %>';
window.location.href = (homelink);
returndata = data;
},
error: function (xhRequest, ErrorText, thrownError) {
alert("Failed to process promotion correctly, please try again");
console.log('xhRequest: ' + xhRequest + "\n");
console.log('ErrorText: ' + ErrorText + "\n");
console.log('thrownError: ' + thrownError + "\n");
}
});
benziyor Ve benim MVC denetleyicisi şöyle görünür: Ben sözdizimi düşünmüştü
[HttpPost]
public HttpResponseMessage ApprovePromotion(PromotionDecision decision)
{
if (ModelState.IsValid && decision != null)
{
bool status = PromotionBo.ApprovePromotion(decision);
if (status == true)
return new HttpResponseMessage(HttpStatusCode.OK);
}
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
her ikisinde de doğruydu ama ajax çağrısını her yaptığımda 400 yanıt aldım. Ben yanlış yapıyorum nedir?
Evet, bunun bir şekilde kırıldığını ve yukarıdaki kodun iki düz saat boyunca üzerinde çalıştıktan sonra olan ve gittikçe hayal kırıklığına uğramış olduğunu anladım. Bunu bir adım atıp çalıştığı zaman cevap olarak işaretleyeceğim. – Pseudonym
Mükemmel çalıştı, yardımsever ve bilgilendirici cevabınız için teşekkürler. – Pseudonym
Harika cevap ... – Mark