一个页面上两个ajax,ajax - 从一个页面上的多个文件请求数据?

我建立了一个数据处理程序“类”只管理这样的事情。你是对的,一个压倒另一个。我还没有调查过它,但它可能是因为你正在重新分配AJAX使用的onEvent。

下面是我建立的类(我知道,这不是JQuery的...它的工作原理)。它所做的是使用超时来“知道”何时触发第二个和第三个异步请求。可能有一个JQuery函数可以做同样的事情。

dataHandler = new DataHandler("[name of datafile to call]");

dataHandler.query['[myQueryName]'] = 'myValue' //this is an Object used to build a query string, if needed, so use as many data pairs as you need

dataHandler.asynchronous(myOnReadyStateChangeFN);//put the fn you want to use for readystatechange as a reference... do not includ the()

这里的“类”:

function DataHandler(dataFile){

this.dataFile = dataFile;

dataInProgress = false;

this.query = new Object();

this.asynchronous = function(fn){

var thisFunction = this.asynchronous

var rand = Math.floor(Math.random()*100001);

var query, timeOutFunctionString;

if(this.dataInProgress){

timeOutFunctionString = callingObjectName+".asynchronous("+fn+")";

this.thisTimeout = setTimeout(timeOutFunctionString,500);

}else{

dataInProgress = true;

this.assignRequestObject.xmlHttp.onreadystatechange = function() {

fn();

dataInProgress = false;

return;

};

}

query = this.dataFile + '?r=' + rand;

for (var key in this.query) query = query + '&' + key + '=' + this.query[key];

//console.info("DataHandler.asynchronous\nquery = "+query+'\nthis.dataFile = ' + this.dataFile);

this.assignRequestObject.xmlHttp.open('GET', query, true);

this.assignRequestObject.xmlHttp.send(null);

};

this.AssignRequestObject = function() {

try { this.xmlHttp = new XMLHttpRequest() } catch (e) {

try { this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {

try { this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") } catch (e) {

alert("Your browser does not support AJAX!");

return false

}

}

}

};

this.assignRequestObject = new this.AssignRequestObject();

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值