Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data from jquery ajax request not working

I have a post request from jquery ajax to a ActionResult method as follow :

$("#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 ...});}

And in controller, ActionResult is :

    [HttpPost]
    public ActionResult GetReportLast5SellAndBuy(string ItemCode)
    { ... somthings ...}

But when ActionResult is called " ItemCode " is null... What's wrong with this chapter?

I tried different forms of this recipe, but the problem is still there..

like image 233
Majid821 Avatar asked Apr 10 '26 15:04

Majid821


1 Answers

try this:

 $.ajax({
        type: "POST",
        url: GetReportLast5SellAndBuyURL,
        data: JSON.stringify({ItemCode:itemCode}),
        datatype: "JSON",
        contentType: "application/json; charset=utf-8",
        processData: false
    }).done(function (msg) { ... somethings ...});}
like image 83
Ajay Kumar Oad Avatar answered Apr 12 '26 05:04

Ajay Kumar Oad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!