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
Post a Comment