【问题标题】:using arraylist that pass to jquery ajax使用传递给jquery ajax的arraylist
【发布时间】:2012-08-05 07:18:45
【问题描述】:

嗨,我有一个 Web 方法,它可以将数据库的数据传递给 jquery ajax 函数,但我不知道它是否可以将 arraylist 传递给 jquery 和 jquery 是否能够识别它,如果答案是好的 如何我可以在 jquery ajax 中使用数组列表。 这是我的代码

  [WebMethod]
    public ArrayList bringdata()
    {
        SqlConnection con = new SqlConnection("data source=.;database=site;integrated security=true;");
        int cnt;
        string sSQL = "Select username ,average,weight,point , Rank() over(order by point desc) as 'ranking' from karbar order by point desc";
        SqlCommand cmd = new SqlCommand(sSQL, con);

        SqlDataAdapter adapt = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adapt.Fill(ds);
        ArrayList arrlst = new ArrayList();
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            arrlst.Add(row);
        }
        return arrlst;


    }

请在 jquery 代码中帮助我使用 arraylist。 非常感谢

【问题讨论】:

  • 我不懂 C# 和 asp.net,但我猜你可以将 ArrayList 输出为 JSON 并在客户端解析它
  • 你是对的,但是在 jquery 中使用 arraylist 的任何解决方案都存在???
  • 你在 JavaScript 中有数组,或者 Objects 可能是 C# ArrayLists 的代表

标签: c# jquery asp.net ajax c#-4.0


【解决方案1】:
<script type = "text/javascript">
function Getdata() {
    PageMethods.bringdata(OnSuccess);
}
function OnSuccess(response) {       
    for (var i in response) {
        alert(response[i]);
    }
} 
</script>

您将编写代码以根据需要在页面上附加数据,而不是警报。

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 2013-06-29
    • 1970-01-01
    • 2018-02-18
    • 2014-06-12
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多