Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send an bool array as an Ajax request:
array name=songs[]
data1 = "{'songs':" + songs + "}";  ==>data1="{'songs':[true,false,flase]}"

               $.ajax({
                   url: "WebService.cs/downloadSelectedSongs",
                   dataType: "json",
                   type: "POST",   //use only POST!
                   data: { songs: songs },
                   contentType: "application/json; charset=utf-8",
                   error: function () {
                       alert("errrrror");
                   },
                   success: function (data) {
                       alert(data.d);
                   }
               });

this is the header of the service:
[WebMethod]
    public string  downloadSelectedSongs(bool[] songs)
    {
      return "ok";
    }


please helpppppppppp:)
Posted
Comments
Member 10631195 20-Sep-14 8:33am    
** data:data1

1 solution

See in following way
$.ajax({
                    url: "WebService.cs/downloadSelectedSongs",
                    dataType: "json",
                    type: "POST",   //use only POST!
                    data: {songs: ['true', 'false', 'false'] },
                    contentType: "application/json; charset=utf-8",
                    error: function () {
                        alert("errrrror");
                    },
                    success: function (data) {
                        alert(data.d);
                    }
                });

In webmethod should be
[WebMethod]
    public static string downloadSelectedSongs(bool[] songs)
    {
      return "ok";
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900