views:

306

answers:

2

I have am using a sortable jQuery list. I would like to send the results of that list to a webmethod for processing.

So my javascript is something like:

function ProcessSortableList() {
    var arr = {};

    arr[0] = "item1";
    arr[1] = "item2";
    PageMethods.TestMe(arr);
}

I then have a webmethod on the server side:

    [WebMethod]
    public static String TestMe(String[] items)
    {
        ... Do stuff here ...
    }

The web method doesn't get called. If I change the webmethod so it takes a single parameter ...

TestMe(string item)

... and then I call it with a single value

PageMethods.Test('item1')

everything works fine.

What gives?

+1  A: 

This doesn't answer your question on why or what's incorrect, but worst case scenario you could send your array of strings just as a pipe delimited string.

var stuff = "item1|item2";

Send that over and just do

var strings = item.Split('|');
Chris Marisic
That's an interesting idea. Thanks Chris.
Daniel
A: 

Change

var arr = {}

to

var arr = new Array()

Daniel
var arr = [] is preferable.
seth
good to know - thanks
Daniel