温故AjaxPro系列之二

      上一篇文章讲到的例子“输出Hello AjaxPro!".其实客户端调用的js中,_Default.Hello(),可以再添加一个可选的参数。这个参数的异步请求后的CallBack函数。CallBack函数中的有一个参数,它接收了response对象。参数的主要属性如下:

value

服务器端返回的真实值

error

任何错误信息

request

xml http request 的原始请求对象.

context

上下文对象

       修改后的Default.aspx代码如下:

代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AjaxProDemo._Default" %>

<!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 type="text/javascript" >
     
function GetHello()
     {
         
var Ret = _Default.Hello(CallBack);
         
//alert(Ret.value);
         return;
     }
     
     
function CallBack(response)
     {
        
if(response.error != null)
        {
            alert(response.error);
            
return;
        }
        alert(response.value);
     }
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
        
<input id="Hl_Bth1" type="button" value="Hello"  onclick="GetHello();"/>
        
    
</form>
     
</body>
</html>

运行后,结果跟上次的一样。

原文地址:https://www.cnblogs.com/luoguoqiang1985/p/1674752.html