后台代码:

 [WebMethod]
public static string CreateDate(string name,string age)
{
return "姓名:"+name +"年龄:"+ age;
} [WebMethod]
public static string CreateInfo()
{
return "调用成功";
} [WebMethod]
public static List<string> CreateString(string num)
{
List<string> list = new List<string>();
for (int i = ; i < Convert.ToInt32(num); i++)
{
list.Add(i+",");
}
return list;
} 前台代码:
 </div>
<input type="button" id="btn" value="点击调用后台无参方法" />
<input type="button" id="btn1" value="点击调用后台有参方法" />
<input type="button" id="btn2" value="点击调用后台返回集合的方法" />
</form> <script> $(function () {
$("#btn").click(function () {
$.ajax({
type:"Post",
url: "index1.aspx/CreateInfo",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "",
success: function (data) {
alert(data.d);
},
error:function(err){
alert("调用失败")
}
});
}); $(function () {
$("#btn1").click(function () {
$.ajax({
type: "Post",
url: "index1.aspx/CreateDate",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'name':'符越涵','age':'25'}",
success: function (good) { alert(good.d) },
error: function (err) { alert("调用错误") }
});
});
}); $("#btn2").click(function () {
$.ajax({
type: "Post",
url: "index1.aspx/CreateString",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:"{'num':'50'}",
success: function (data) {
$(data.d).each(function () {
alert(this)
});
},
error: function (err) {alert("调用错误") }
});
});
});
</script>
04-26 13:01