实现发送多个Ajax请求

王朝学院·作者佚名  2009-11-04
窄屏简体版  字體: |||超大  

目的是实现了,个人觉得在执行速度上不是很理想,希望大家帮忙改进,谢谢!

大家知道IE只能一次发送一个Ajax请求,你是否尝试过在一个页面上用Ajax请求多次,虽然可以实现我们发现代码很乱

我们来实现一个在页面呈现缓存的例子吧!

//获取Dom

function $(id) { return document.getElementById(id); }

思路:我们把要加载的缓存放在一个集合中,再迭代集合实现所有的获取缓存请求

var cache={page:"Index",id:"Courses",element:$("Courses")};

//page为加载的缓存页面 id缓存ID,element显示缓存的Dom对象

顺便插一句:这个例子用Jquery实现的了吗?可以尝试一下,呵呵,这几天好像跟Jquery有仇一样

上面定义了缓存对象,下面的代码就创建一个请求Ajax的方法,我们称之为: AsyncRequest

var xmlHttp = null;

function $AsyncRequest(request, callback) {

this.method = request.method!=null&&request.method.toLowerCase()=="post"?"POST":"GET";

this.url = request.url;

this.params = request.params;

this.dataType =request.dataType!=null&&request.dataType.toLowerCase() == "xml" ? "xml" : "text";

this.async = request.async instanceof Boolean ? request.async : true;

if (callback != null) {

this.success = callback.success;

this.error = callback.error;

if (callback.start != null) callback.start();

}

if (xmlHttp == null

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航