jquery ajax get an array of parameters

Some get request, but the method requires an array or a set of parameters, as follows

       public virtual ActionResult Test(List<int> ids)
        {
            return Json("");
        }

Is a collection of parameter ids request mode

http://www.XX.com/test?ids=1&ids=2

The above values ​​written will receive ids 1 and 2

If a get ajax mode request, in addition to directly fight url, but this can also be written

           var ids = new Array();
            ids.push(1);
            ids.push(2);
$.ajax({ type:
"get", traditional:true, url: "/test", data: { ids: ids }, dataType: "json", success: function (res) { } });

 

Set traditional: true to

So do not fight the url

 

Guess you like

Origin www.cnblogs.com/evemen/p/11110546.html