[英]Send data from jquery ajax request not working
我有一個從jquery ajax到ActionResult方法的帖子請求,如下所示:
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
var GetReportLast5SellAndBuyURL="/Trd/SellInvoice/GetReportLast5SellAndBuy";
itemCode = $(this).val();
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: {ItemCode:itemCode},
//contentType: "application/json; charset=utf-8",
context: this,
processData: false
}).done(function (msg) { ... somethings ...});}
在控制器中,ActionResult是:
[HttpPost]
public ActionResult GetReportLast5SellAndBuy(string ItemCode)
{ ... somthings ...}
但是當調用ActionResult時,“ItemCode”為空......本章有什么問題?
我嘗試了不同形式的這個食譜,但問題仍然存在..
嘗試這個:
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: JSON.stringify({ItemCode:itemCode}),
datatype: "JSON",
contentType: "application/json; charset=utf-8",
processData: false
}).done(function (msg) { ... somethings ...});}
只需在腳本中注釋processData:false即可
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
var GetReportLast5SellAndBuyURL="/Trd/SellInvoice/GetReportLast5SellAndBuy";
itemCode = $(this).val();
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: {ItemCode:itemCode},
//contentType: "application/json; charset=utf-8",
context: this
// processData: false
}).done(function (msg) { ... somethings ...});}
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) { if ((e.keyCode == 120){ $.ajax({ type: "POST", url: "/Trd/SellInvoice/GetReportLast5SellAndBuy?ItemCode="+$(this).val(), contentType: "application/json", context: this, datatype: "JSON", processData: false }).done(function (msg) { ... somethings ...});} // OR $("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) { if ((e.keyCode == 120){ $.ajax({ type: "POST", url: "/Trd/SellInvoice/GetReportLast5SellAndBuy", contentType: "application/json", data:JSON.stringify({ItemCode:$(this).val()}) datatype: "JSON", context: this, processData: false }).done(function (msg) { ... somethings ...});}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.