views:

105

answers:

2

in something like :

$.ajax({

   type: "POST",    
   url: "WebService1.asmx/SendValues",    
   data: jsonText,    
   contentType: "application/json; charset=utf-8",    
   dataType: "json",    
   success: function() { alert("it worked"); },    
   failure: function() { alert("Uh oh"); }

   });

how do I send more than one array to a Web Service? Is it possible? Or should i send multi-dimensional array?

+1  A: 

Assuming your the web service you're talking to is ready for that, I suggest going to multi-array route. An array in json would look like:

[1,2,3]

So, you could pass multiple arrays in an array like this:

[[1,2,3],[4,5,6]]
Jage
so in other words, I have to do nasty unpacking if I want to pass more than one param to my web service (which is not unheard of).great....
gnomixa
so how would send this in my javascript code?data: ......
gnomixa
+1  A: 

I got it: in my javascript I have:

function Save() {
     var list = [["1","2","3"],["4","5","6"],["34","88","898"]];
     var jsonText = JSON.stringify({ list: list });

     $.ajax({
         type: "POST",
         url: "http://localhost/TemplateWebService/TemplateWebService/Service.asmx/SaveSampleTemplate",
         data: jsonText,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function(response) {
             //var arrSamples = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
         alert("success!");

             alert(response.d);


         },

         failure: function(msg) {

             alert("fail");                 

         }

     });

}

then in my web service (asp.net web service):

[WebMethod()]
        public string SaveSampleTemplate(string[][] list)
        {

            List<string[]> mylist = list.ToList();


           // return list.Count.ToString();
            string str = "";
            for (int i = 0; i < mylist.Count; i++)
            {
                string[] m = mylist[i];

                for (int j = 0; j < m.Length; j++)
                {
                    str += m[j] + " ";
                }

            }
            return str;

          // return list.Length.ToString();
        }
gnomixa