AjaxPro.Utility.RegisterTypeForAjax(typeof(Resin));
使用上面的方法注册当前页面,运行后在页面中加入下面两句
<script type="text/javascript" src="/AJAXDemo/ajaxpro/core.ashx"></script>
<script type="text/javascript" src="/AJAXDemo/ajaxpro/AJAXDemo.Resin,AJAXDemo.ashx"></script>
<script language="javascript">
var response = Sample.ServerSideAdd(100,99);
alert(response.value);
</script>
增加客户端可调用方法
public int ServerSideAdd(int firstNumber, int secondNumber)
{
return firstNumber + secondNumber;
}
客户端调用
<form id="Form1" method="post" runat="server">
<script language="javascript">
var response = AJAXDemo.Resin.ServerSideAdd(100,99);
alert(response.value);
</script>
</form>
同时可以改下如下,这样会返回一个response对象,可以对程序异常进行处理
<form id="Form1" method="post" runat="server">
<script language="javascript">
//var response = AJAXDemo.Resin.ServerSideAdd(100,99);
//alert(response.value);
AJAXDemo.Resin.ServerSideAdd(100,99,ServerSideAdd_CallBack);
function ServerSideAdd_CallBack(response){
if (response.error != null){
alert(response.error);
return;
}
alert(response.value);
}
</script>
</form>
处理dataset的例子
服务端
public DataSet GetDataSet()
{
// SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings["connString"], "GetHostitalListByPymAndGroupid",querycode,groupid);
DataSet myds = new DataSet();
myds=SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["connString"],CommandType.Text,"Select top 10 ypm,gg,cd,zxdw from zy_sys2_ypzdk");
return myds;
}
客户端
<script language="javascript">
AJAXDemo.Resin.GetDataSet(GetDataSet_CallBack);
function GetDataSet_CallBack(response){
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
var s = new Array();
s[s.length] = "<table border=1>";
for(var i=0; i<ds.Tables[0].Rows.length; i++){
s[s.length] = "<tr>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].ypm + "</td>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].gg + "</td>";
s[s.length] = "</tr>";
}
s[s.length] = "</table>";
alert(s.join(""));
}
else
{
alert("Error. [3001] " + response.error);
}
}
</script>