从jQuery Ajax请求发送数据不起作用

时间:2019-09-04 06:44:51

标签: javascript jquery ajax

我有一个从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”为null时...本章怎么了?

我尝试过这种食谱的不同形式,但问题仍然存在。

3 个答案:

答案 0 :(得分:2)

尝试一下:

import math
import time

start = time.time()
high, low = (1, 1)
md = 1000000000
seen = set()
for i in range(2, 1000000):
    summ = 1 + i + math.pow(i, 2)
    power = 2
    while summ < 10 ** 12:
        if summ not in seen:
            seen.add(summ)
            high += summ
            low += summ
            low %= md
        power += 1
        summ += math.pow(i, power)

print(high // md, low)
end = time.time(

答案 1 :(得分:1)

只需在脚本中注释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 ...});}

在[Setting processData to false in jQuery breaks my AJAX request

进行了解释

答案 2 :(得分:-1)

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

相关问题