Passing jquery search results to a page method
-
16-09-2019 - |
Question
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?
Solution 2
Change
var arr = {}
to
var arr = new Array()
OTHER TIPS
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('|');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow