如何使用Ajax
使用Ajax步骤如下:
一、引用Ajax.dll类库至项目中。
二、设置Web.Config文件:
1 <configuration>
2 <system.web>
3 <httpHandlers>
4 <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
5 </httpHandlers>
6
7 <system.web>
8 </configuration>
2 <system.web>
3 <httpHandlers>
4 <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
5 </httpHandlers>
6

7 <system.web>
8 </configuration>
三、设置Page_Load():
1 Ajax.Utility.RegisterTypeForAjax(typeof(Index)); //Index为你当前页面所使用的类
四、创建方法:
1 [Ajax.AjaxMethod()]
2 public int ServerSideAdd(int firstNumber, int secondNumber)
3 {
4 return firstNumber + secondNumber;
5 }
五、客户端来调用上面所创建的方法:2 public int ServerSideAdd(int firstNumber, int secondNumber)
3 {
4 return firstNumber + secondNumber;
5 }
1 function CallBack()
2 {
3 var Data = Index.ServerSideAdd(100,99).value;
4 alert(Data);
5 }
6 或者:
7 function CallBack()
8 {
9 Index.ServerSideAdd(100,99, ServerSideAdd_CallBack);
10 }
11 function ServerSideAdd_CallBack(response){
12 alert(response.value);
13 }
OK,到此为止已大功告成,当然你可以任意发挥,做出你想要的效果。
2 {
3 var Data = Index.ServerSideAdd(100,99).value;
4 alert(Data);
5 }
6 或者:
7 function CallBack()
8 {
9 Index.ServerSideAdd(100,99, ServerSideAdd_CallBack);
10 }
11 function ServerSideAdd_CallBack(response){
12 alert(response.value);
13 }
浙公网安备 33010602011771号