gọi ajax của tôi trông như thế nàyLiên tục nhận 400 (Yêu) về jquery ajax đường bưu điện đến bộ điều khiển MVC
$.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");
}
});
Và điều khiển MVC của tôi trông như thế này:
[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);
}
Tôi đã nghĩ cú pháp là chính xác trên cả hai trong số này tuy nhiên mỗi khi tôi thực hiện cuộc gọi ajax tôi nhận được một phản ứng 400. Tôi đang làm gì sai?
vâng tôi đã nghĩ rằng nó đã bị hỏng bằng cách nào đó và mã ở trên là những gì xảy ra sau khi bạn đã làm việc trên nó trong hai giờ liên tục và đã nhận được ngày càng thất vọng. Tôi sẽ cung cấp cho nó một đi và đánh dấu nó như là câu trả lời khi nó hoạt động. – Pseudonym
Nó hoạt động hoàn hảo, nhờ câu trả lời hữu ích và mang tính thông tin của bạn. – Pseudonym
Câu trả lời hay ... – Mark