tags:

views:

538

answers:

3

here's my code:

var ids = $.map($("#container-1").children(), function(n, i) {
     return n.id;
});

$.ajax({
    type: 'POST',
    url: 'Loader.asmx/Active',
    data: "{'divs':'" + ids + "'}",
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {}
});
A: 

I wouldn't think you'd need to render your data as a string.

Wouldn't this work?

data: { divs: ids },

Assuming that ids is a JavaScript string array, that is.

David
A: 

Javascript;

var ids = $.map($("#container-1").children(), function(n, i) {
     return n.id;
});

$.ajax({
    type: 'POST',
    url: 'Loader.asmx/Active',
    data: { divs: ids.join("|") },
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {}
});

in C#:

string[] arrIds = divs.Split('|');
andres descalzo
+2  A: 

http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax-to-an-aspnet-webmethod/

this is the answer, thanks!

Martin Ongtangco
this works beautifully for me :)
danrichardson