Pass array to ajax request in $.ajax()

后端 未结 2 1674
梦毁少年i
梦毁少年i 2021-01-22 14:48

I have tried like this but could not get array list. It returns \'null\'

 var data=[];
 data[0] = \'1\';
 data[1] = \'2\';
    $.ajax({                    
              


        
相关标签:
2条回答
  • 2021-01-22 15:25
    var datas = { data0: '1',
          data1: '2' };
    $.ajax({                    
             url: '@Url.Action("AddFrequencyWeekly", "Plannar")',
             type: "POST",                     
             data: datas,
             dataType: 'json', 
             success: function (data) {                                            
                 alert("Record Updated Successfully");    
                     }
             });
    
    0 讨论(0)
  • 2021-01-22 15:44

    Its the way you are expecting to recive the data in the action method, try

    public JsonResult AddFrequencyWeekly(IEnumeable<string> data)
    {
    
    }
    
    0 讨论(0)
提交回复
热议问题