MicrosoftMvcAjax的异步调用回调函数(onFailure、onSuccess)研究

由asp.net mvc的MicrosoftMvcAjax中主要要以下两个ajax类型:

  • Ajax.ActionLink
  • Ajax.FormBegin

由Ajax.ActionLink产生的html代码(mvc示例:ContantManager)如下:

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
< a groupid ="23" href ="/Contact/Index/23"
onclick
="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event),
{ insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'divContactList1',
onBegin: Function.createDelegate(this, beginContactList),
onFailure: Function.createDelegate(this, failureContactList),
onSuccess: Function.createDelegate(this, successContactList) });"
>
private string
</ a >

 

当点击此链接,服务器执行成功调用onSuccess回调函数,执行失败调用onFailure回调函数。

 

onSuccess函数与onFailure函数的原型如下:

ajaxOptions.onSuccess(ajaxContext);

ajaxOptions.onFailure(ajaxContext);

这两个函数都有一个参数ajaxContext。

 

参数ajaxContext用法说明:

  • 显示服务器返回内容: alert(ajaxContext.get_data());
  • 服务器返回内容类型:alert(ajaxContext.get_response().getResponseHeader('Content-Type'));

参数ajaxContext代码如下:

文件MicrosoftMvcAjax.debug.js第33行

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
// //
//
Sys.Mvc.AjaxContext

Sys.Mvc.AjaxContext
= function Sys_Mvc_AjaxContext(request, updateTarget, loadingElement, insertionMode) {
// / <param name="request" type="Sys.Net.WebRequest">
// / </param>
// / <param name="updateTarget" type="Object" domElement="true">
// / </param>
// / <param name="loadingElement" type="Object" domElement="true">
// / </param>
// / <param name="insertionMode" type="Sys.Mvc.InsertionMode">
// / </param>
// / <field name="_insertionMode" type="Sys.Mvc.InsertionMode">
// / </field>
// / <field name="_loadingElement" type="Object" domElement="true">
// / </field>
// / <field name="_response" type="Sys.Net.WebRequestExecutor">
// / </field>
// / <field name="_request" type="Sys.Net.WebRequest">
// / </field>
// / <field name="_updateTarget" type="Object" domElement="true">
// / </field>
this ._request = request;
this ._updateTarget = updateTarget;
this ._loadingElement = loadingElement;
this ._insertionMode = insertionMode;
}
Sys.Mvc.AjaxContext.prototype
= {
_insertionMode:
0 ,
_loadingElement:
null ,
_response:
null ,
_request:
null ,
_updateTarget:
null ,

get_data:
function Sys_Mvc_AjaxContext$get_data() {
// / <value type="String"></value>
if ( this ._response) {
return this ._response.get_responseData();
}
else {
return null ;
}
},

get_insertionMode:
function Sys_Mvc_AjaxContext$get_insertionMode() {
// / <value type="Sys.Mvc.InsertionMode"></value>
return this ._insertionMode;
},

get_loadingElement:
function Sys_Mvc_AjaxContext$get_loadingElement() {
// / <value type="Object" domElement="true"></value>
return this ._loadingElement;
},

get_response:
function Sys_Mvc_AjaxContext$get_response() {
// / <value type="Sys.Net.WebRequestExecutor"></value>
return this ._response;
},
set_response:
function Sys_Mvc_AjaxContext$set_response(value) {
// / <value type="Sys.Net.WebRequestExecutor"></value>
this ._response = value;
return value;
},

get_request:
function Sys_Mvc_AjaxContext$get_request() {
// / <value type="Sys.Net.WebRequest"></value>
return this ._request;
},

get_updateTarget:
function Sys_Mvc_AjaxContext$get_updateTarget() {
// / <value type="Object" domElement="true"></value>
return this ._updateTarget;
}
}

 


 


转载于:https://www.cnblogs.com/StrongWind/archive/2010/05/05/ajaxfunction.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值