如何将数组发送到.net中的ajax到websevice [英] how to send array to ajax to websevice in .net

查看:64
本文介绍了如何将数组发送到.net中的ajax到websevice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送一个bool数组作为Ajax请求:

数组名称=歌曲[]

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";
    }





请helpppppppppp:)



please helpppppppppp:)

推荐答案

。 ajax({
url:WebService.cs / downloadSelectedSongs,
dataType:json,
type:POST,//仅使用POST!
data:{歌曲:歌曲},
contentType:application / json; charset = utf-8,
错误:function(){
alert(errrrror);
},
成功:函数(数据){
alert(data.d);
}
});
.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";
    }





请helpppppppppp:)



please helpppppppppp:)


请按以下方式查看

See in following way


.ajax({
url:WebService.cs / downloadSelectedSongs,
dataType:json,
类型:POST,//仅使用POST!
数据:{songs:['true','false','false']},
contentType:application / json; charset = utf-8,
error:function(){
alert(errrrror);
},
success:function(数据){
alert(data.d);
}
});
.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); } });



在web方法中应该是


In webmethod should be

[WebMethod]
    public static string downloadSelectedSongs(bool[] songs)
    {
      return "ok";
    }


这篇关于如何将数组发送到.net中的ajax到websevice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆