jQuery Ajax POSTing array to ASP.NET MVC Controller

后端 未结 2 1161
礼貌的吻别
礼貌的吻别 2020-11-29 01:05

I\'m missing something here. I\'ve got this jQuery JavaScript:

$.ajax({
    type: \"POST\",
    url: \"/update-note-order\",
    dataType: \"json\",
    data         


        
相关标签:
2条回答
  • 2020-11-29 01:53

    Just set the traditional parameter to true:

    $.ajax({
        type: "POST",
        url: "/update-note-order",
        dataType: "json",
        traditional: true,
        data: {
            orderedIds: orderedIds,
            unixTimeMs: new Date().getTime()
        }
    });
    

    Since jquery 1.4 this parameter exists because the mechanism to serialize objects into query parameters has changed.

    0 讨论(0)
  • 2020-11-29 01:53

    you'll need to turn orderedId's into a param array, or the controller won't see it

    $.param({ orderedIds: orderedIds });  
    

    in your code:

    $.ajax({
        type: "POST",
        url: "/update-note-order",
        dataType: "json",
        data: {
            orderedIds: $.param({ orderedIds: orderedIds }),
            unixTimeMs: new Date().getTime()
        }
    });
    
    0 讨论(0)
提交回复
热议问题