网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 网页素材 > AJAX代码 > 正文
Ajax学习笔记
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: Admin 发布时间: 09/04/17

//页面首次加载过程:
Utility.RegisterTypeForAjax :
将以下脚本注册:
<script type="text/javascript" src="/AjaxPro.Sample/ajaxpro/prototype.ashx"></script>
<script type="text/javascript" src="/AjaxPro.Sample/ajaxpro/core.ashx"></script>
<script type="text/javascript" src="/AjaxPro.Sample/ajaxpro/converter.ashx"></script>
<script type="text/javascript" src="/AjaxPro.Sample/ajaxpro/AjaxPro.Sample.Sample_1,AjaxPro.Sample.ashx"></script>
.net运行框架调用以下方法:
AjaxHandlerFactory.GetHandler
1.由于.ashx被注册为自定义处理,此方法被调用4次;
2.依据请求类型(get)和请求的目标进行分别处理,分别对应EmbeddedJavaScriptHandler(2次),ConverterJavaScriptHandler(1次),TypeJavaScriptHandler(1次)
3..net运行框架在AjaxHandlerFactory.GetHandler返回不同的IHttpHandler实现(EmbeddedJavaScriptHandler等)时调用该实现的以下方法:
EmbeddedJavaScriptHandler.ProcessRequest方法被调用:
EmbeddedJavaScriptHandler.ProcessRequest方法被调用:
ConverterJavaScriptHandler.ProcessRequest方法被调用:
TypeJavaScriptHandler.ProcessRequest方法被调用:
向客户端输出以下代码:
addNamespace("AjaxPro.Sample");
AjaxPro.Sample.Sample_1_class = Class.create();
AjaxPro.Sample.Sample_1_class.prototype = (new AjaxPro.AjaxClass()).extend(
{
              GetServerTime: function() 
              {
                            return this.invoke("GetServerTime", {}, this.GetServerTime.getArguments().slice(0));
              },
              AddTwo: function(firstInt, secondInt) 
              {
                            return this.invoke("AddTwo", {"firstInt":firstInt, "secondInt":secondInt}, this.AddTwo.getArguments().slice(2));
              },
              initialize: function() 
              {
                            this.url = ''/AjaxPro.Sample/ajaxpro/AjaxPro.Sample.Sample_1,AjaxPro.Sample.ashx'';
              }
});
AjaxPro.Sample.Sample_1 = new AjaxPro.Sample.Sample_1_class();
//分析prototype.js
var Class = {
              create: function() {
                            return function() {
                                                                      if(typeof this.initialize == "function")
                                                                      this.initialize.apply(this, arguments);
                                          }
                            }
}
AjaxPro.AjaxClass = Class.create();
AjaxPro.AjaxClass.prototype = {
              initialize: function(url) {
                            this.url = url;
              },
              invoke: function(method, args, e) {
                            if(e != null) {
                                          if(e.length != 6) for(;e.length<6;) e.push(null);
                                          if(e[2] == null) e[2] = this.onLoading;
                                          if(e[2] == null) e[3] = this.onError;
                                          if(e[2] == null) e[4] = this.onTimeout;
                                          if(e[2] == null) e[5] = this.onStateChanged;
                                          if(typeof e[0] == "function") {
                                                        return AjaxPro.queue.add(this.url, method, args, e);
                                          }
                            }
                            var r = new AjaxPro.Request();
                            r.url = this.url;
                            r.onLoading = this.onLoading;
                            r.onError = this.onError;
                            r.onTimeout = this.onTimeout;
                            r.onStateChanged = this.onStateChanged;
                            return r.invoke(method, args);
              }
};
AjaxPro.Request = Class.create();
AjaxPro.Request.prototype = {
              invoke: function(method, args, callback, context) {
                            this.__start = new Date().getTime();
                            this.isRunning = true;
                            this.method = method;
                            this.args = args;
                            this.callback = callback;
                            this.context = context;
  
                            if(MS.Debug.enabled == true)
                            MS.Debug.trace("Invoking " + method + "...");

                            var async = typeof callback == "function" && callback != AjaxPro.noOperation;
                            var json = AjaxPro.toJSON(args) + " ";

                            if(AjaxPro.cryptProvider != null)
                            json = AjaxPro.cryptProvider.encrypt(json);

                            if(async) {
                                                        this.xmlHttp.onreadystatechange = this.doStateChange.bind(this);
                                                        if(typeof this.onLoading == "function") this.onLoading(true);
                            }

                            this.xmlHttp.open("POST", this.url, async);
                            this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                            this.xmlHttp.setRequestHeader("Content-Length", json.length);
                            this.xmlHttp.setRequestHeader("Ajax-method", method);
  
                            if(AjaxPro.token != null && AjaxPro.token.length > 0)
                            this.xmlHttp.setRequestHeader("Ajax-token", AjaxPro.token);

                            if(MS.Browser.isIE)
                                                        this.xmlHttp.setRequestHeader("Accept-Encoding", "gzip, deflate");
                            else
                                                        this.xmlHttp.setRequestHeader("Connection", "close");  // Mozilla Bug #246651

                            if(this.onTimeout != null && typeof this.onTimeout == "function")
                            this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);

                            this.xmlHttp.send(json);
  
                            json = null;
                            args = null;
                            delete json;
                            delete args;
  
                            if(!async) {
                                                        return this.createResponse();
                            }
  
                            return true; 
              }
}
//当用户触发UI控件动作时
1.由于生成的客户端脚本中包含对于"/AjaxPro.Sample/ajaxpro/AjaxPro.Sample.Sample_1,AjaxPro.Sample.ashx"的调用,导致AjaxHandlerFactory.GetHandler被调用
2.在AjaxHandlerFactory.GetHandler中返回AjaxSyncHttpHandler
3..net运行框架在AjaxHandlerFactory.GetHandler返回不同的IHttpHandler实现(AjaxSyncHttpHandler等)时调用该实现的以下方法:
AjaxSyncHttpHandler.ProcessRequest方法被调用:
将调用转嫁到AjaxProcHelper.Run操作:
1.通过反射实现对指定C#类方法的调用.
2.将反射调用结果通过XmlHttpRequestProcessor.SerializeObject中对JavaScriptSerializer.Serialize的调用通过Response向客户端返回. 

  • 上一篇资讯: 使用JSON 进行数据传输
  • 下一篇资讯: 用Ajax读写操作Session()
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 电话:013574892963 QQ:3710167 邮箱:Educs@163.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 Www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号