问点问题

手可摘星辰 2012-08-22 02:41:06
$(function() {
$("#btnOK").click(function() {
$.ajax({
type: "Post",
url: "demo.aspx/GetArray",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
//插入前先清空ul
$("#list").html("");

//递归获取数据
$(data.d).each(function() {
//插入结果到li里面
$("#list").append("<li>" + this + "</li>");
});

alert(data.d);
},
error: function(err) {
alert(err);
}
});

//禁用按钮的提交
return false;
});
});

那个d哪来的
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
手可摘星辰 2012-08-22
  • 打赏
  • 举报
回复
再发一遍吧,混了
,源码是这样额

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$.ajax({
type: "POST",
url: "AJAX.aspx/GetStr",
data: "{'str':'我是','str2':'XXX'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data.d);
},
error: function (err) {
alert(err);
}

});
});
});


</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
</div>
</form>
</body>
</html>





[WebMethod]
public static string GetStr(string str, string str2)
{
return str + str2;

}
手可摘星辰 2012-08-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 touzilk 的回复:]
引用 1 楼 return_false 的回复:
后台返回的json {"d":""} 有d这个属性


这个真没有


C# code

[WebMethod]
public static List<string> GetArray()
{
List<string> li = new List<string>();
……
[/Quote]

发错了
这样的

[WebMethod] public static string GetStr(string str, string str2) { return str + str2; }
手可摘星辰 2012-08-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 return_false 的回复:]
后台返回的json {"d":""} 有d这个属性
[/Quote]

这个真没有


[WebMethod]
public static List<string> GetArray()
{
List<string> li = new List<string>();

for (int i = 0; i < 10; i++)
li.Add(i + "");

return li;
}


后台就这样
  • 打赏
  • 举报
回复
后台返回的json {"d":""} 有d这个属性

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧