首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

!asp.net后台接收jquery传数组值

2012-08-29 
请教高手!!!asp.net后台接收jquery传数组值前台代码:div overflow-y:scroll stylepadding-top:10pxpa

请教高手!!!asp.net后台接收jquery传数组值
前台代码:
<div overflow-y:scroll; style="padding-top:10px;padding-left:50px;">
<ul id="tree" class="tree" style="width:300px; border:1px solid #898c95; height:480px; overflow:auto;"></ul>
</div>
  <br />
  <div style="width:300px; padding-left:100px;"><asp:Button CssClass="submit" BorderColor="#6699cc" 
  BorderWidth="1px" Width="84px" ID="Button1" runat="server" Text="确定" 
  onclick="Button1_Click" />
  <asp:Button CssClass="submit" BorderColor="#6699cc" BorderWidth="1px" Width="84px" ID="Button2" runat="server" Text="取消" OnClientClick="javascript:window.close();"
 />
  <asp:Button CssClass="submit" BorderColor="#6699cc" BorderWidth="1px" Width="84px" ID="Button3" runat="server" Text="帮助" />
  <asp:HiddenField ID="permi" runat="server" />
  </div>
   
  <script type="text/javascript">
var zTree;
var demoIframe;

var setting = {
checkable:true,
isSimpleData: true,
treeNodeKey: "Id",
treeNodeParentKey: "PId",
nameCol: "Name",
showLine: true,
root: {
isRoot: true,
nodes: []
}
};
zNodes = [<% = NodesData %>];

$(document).ready(function() {
zTree = $("#tree").zTree(setting, zNodes);

$("#Button1").click(function(){
  var nodes = zTree.getCheckedNodes();
  //$("#<% =permi %>").val(nodes);
  $("#permi").attr("value",nodes);
  for(x in nodes){
  alert(nodes[x]["funcid"]);
  }
  });
  });
</script>

后台代码:

  protected void Button1_Click(object sender, EventArgs e)
  {
  //Response.Write(permission);
  //Response.ContentType = "application/json";
  string permission = this.permi.Value;
  Response.Write(permission); 
  Response.End();
  }

输出的结果总是:[object Object],[object Object],[object Object]

  我是新手,不知道该怎么传这个nodes的值到后台,快急死了,麻烦高手给指点一下,再次谢谢了!!!!!

[解决办法]
<html>
<head></head>
<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function getData() {
var array = [{ a: 1, b: 2 }, { a: 1, b: 2}];
$("#permi").val(array);
alert($("#permi").val());
}
$(document).ready(function() {
$("#Button1").click(function() {
getData();
});
});
</script>
<body>

<form id="form1" runat="server" >
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click1" />


<asp:HiddenField ID="permi" runat="server" />

</form>

</body>
</html> 

提交到后台就是一个对象的集合的字符串,把这个字符串转化为对象集合就好了
[解决办法]
JSON例子

[解决办法]
$("#permi").attr("value",nodes);

你需要自己处理下nodes的数据,再放到#permi中


热点排行