jQuery dialog 异步调用ashx,webservice数据
点击按钮,在弹出的jQuery.dialog中,显示异步返回的数据。
WebService可以写复杂的函数,ashx可以根据传过来的参数调用不同的方法,达到同样的效果。
本文用到了博客园TerryFeng的例子。
Html,JS代码:
代码
Ashx代码:
<%@ WebHandler Language="C#" Class="test" %>
using System;
using System.Web;
public class test : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello A");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
public class test : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello A");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
WebService:
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello C";
}
[WebMethod]
public string HelloA(string a, string b)
{
return "Hello__" + a + "__" + b;
}
[WebMethod]
public List<int> GetArray(int i)
{
List<int> list = new List<int>();
while (i >= 0)
{
list.Add(i--);
}
return list;
}
[WebMethod]
public Class1 GetClass()
{
Class1 cl=new Class1();
cl.ID="qixuejia";
cl.Value="qixuejia.cnblogs.com";
return cl;
}
[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Value", Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Value"] = "qixuejia.cnblogs.com";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = "2";
dr["Value"] = "qixuejia";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}
}
public class Class1
{
private string _ID;
private string _Value;
public string ID
{
get { return _ID; }
set { _ID = value; }
}
public string Value
{
get { return _Value; }
set { _Value = value; }
}
}
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello C";
}
[WebMethod]
public string HelloA(string a, string b)
{
return "Hello__" + a + "__" + b;
}
[WebMethod]
public List<int> GetArray(int i)
{
List<int> list = new List<int>();
while (i >= 0)
{
list.Add(i--);
}
return list;
}
[WebMethod]
public Class1 GetClass()
{
Class1 cl=new Class1();
cl.ID="qixuejia";
cl.Value="qixuejia.cnblogs.com";
return cl;
}
[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Value", Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Value"] = "qixuejia.cnblogs.com";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = "2";
dr["Value"] = "qixuejia";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}
}
public class Class1
{
private string _ID;
private string _Value;
public string ID
{
get { return _ID; }
set { _ID = value; }
}
public string Value
{
get { return _Value; }
set { _Value = value; }
}
}