javascript - How to set Array String through JS Post Back to Web Method? -


how send array strings js post web method in asp.net, code sample below:

function service() {             var items = $('#jqxtree').jqxtree('getcheckeditems');             //  var jsontext = json.stringify({ list: items });             mydata = {};             (index in items) {                 mydata[index] = items[index].label;             }             $.ajax({                 type: "post",                 url: "serviceconfiguration.aspx/processindexes",                 data: "{'jsonvalue': " + json.stringify(mydata) + "}",                 contenttype: "application/json; charset=utf-8",                 datatype: "json",                 async: false,                 cache: false,                 success: function (msg) {                  }             });             //alert(items);         } 

now trying following:

[webmethod(enablesession = true)]         [scriptmethod(responseformat = responseformat.json)]         public static void processindexes(list<string> jsonvalue)         {             var serializer = new javascriptserializer();           } 

been awhile since i've been in .net land, should work:

$.ajax({     type: "post",     url: "someform.aspx/somewebmethod",     data: json.stringify({ somevalues: ["foo", "bar"] }),     contenttype: "application/json",     datatype: "json",     success: function(resp) {         // handle success here     },     error: function() {         // handle error here     } }); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -