Jquery实例中关于Ajax调取数据多集中在页面获取,关于WebService调取介绍很少,这里贴出代码,也是举例性质,后台根据自己情况进行更详细的查询返回。

这里要说明几点:

1、WebService地址必须是全称;

2、数据返回(dataType)为xml,如果要返回Json,代码需要调整;

3、参数写法看实例;

页面部分代码:

 

<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>无标题页</title>
  <script src="jquery.js"></script>
</head>
<body>
  <form ).html($(this).find(arrFiledId[j]).text()).appendTo(tr);
        tr.appendTo(tb);
      })
    }
    </script>
  </form>
</body>
</html>

asmx代码:

 

  [WebMethod]
  public DataSet GetExample(String title, String content)
  ...{
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    dt.Columns.Add("Title", Type.GetType("System.String"));
    dt.Columns.Add("Content", Type.GetType("System.String"));
    DataRow dr = dt.NewRow();
    dr["Title"] = "甲方";
    dr["Content"] = "好了没?";
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr["Title"] = "乙方";
    dr["Content"] = "明天!"+DateTime.Now.ToString("yyyy-M-d H:m:s");
    dt.Rows.Add(dr);
    dr = dt.NewRow();
    dr["Title"] = title;
    dr["Content"] = content;
    dt.Rows.Add(dr);
    ds.Tables.Add(dt);
    return ds;
  }

 

文章来源:http://www.9yuer.com/thread-2057.html

相关文章:

  • 2021-06-08
  • 2021-09-29
  • 2021-09-02
  • 2022-02-08
  • 2022-12-23
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-10-05
  • 2022-03-09
  • 2021-11-04
相关资源
相似解决方案