AJAX Post of JavaScript String Array to JsonResult as List Always Returns Null?

后端 未结 2 658
无人共我
无人共我 2020-12-02 09:08

I\'m trying to build up a string array in JavaScript and get the results in a string list in the action method. Below is what my JavaScript looks like. I\'m using jQuery 1

相关标签:
2条回答
  • 2020-12-02 10:07

    This change was to make native behavior better for PHP/Rails users, you can read about the params changes more here.

    You can enable it per-request like this:

    $.ajax({ 
     //Stuff...
     traditional:true 
    });
    

    Or globally like this (only need to run once before firing any requests):

    jQuery.ajaxSettings.traditional = true;
    
    0 讨论(0)
  • 2020-12-02 10:11

    I faced the same problem after updating to jquery 1.4.2. You can find the solution here (in the Ajax section).

    Adding traditional : true in the ajax options should work.

    $.ajax({
        type: "POST",
        traditional: true,
        url: "/Test/JSONTestAction",
        async: false,
        data: parms,
        dataType: "json",
        success: function(data) {
    
            // success
        }
    });
    
    0 讨论(0)
提交回复
热议问题