页面中有一个链接,例如单击该链接时,ajax 将成功运行,但是当单击此链接时,我该怎么做?运行多个 ajax 调用并将相同的查询字符串传递给不同的页面?将获得帮助
问问题
310 次
1 回答
0
var pages = ["page1.php","page2.php","folder/page3.php"]
var requests = [];
function multipleAjax(string) {
/*where string is "?value=somevalue&bool=true" or something*/
for (i=0; i<pages.length;i++) {
requests[i] = getXMLHttpRequest();
if (requests[i] != null) {
requests[i].open("Post", "/" + pages[i] + string);
requests[i].onreadystatechange = function () {
if (requests[i].readyState == 4) {
/*code to handle responseText returned*/
};
};
};
requests[i].send();
};
};
function getXMLHttpRequest() {
var re = "nothing";
try {re = new window.XMLHttpRequest();} catch(e1) {};
try {re = new ActiveXObject("MSXML2.XMLHTTP.4.0");} catch(e) {};
try {re = new ActiveXObject("Msxml2.XMLHTTP");} catch(e2) {};
try {re = new ActiveXObject("Microsoft.XMLHTTP");} catch(e3) {};
try {re = new ActiveXObject("MSXML2.XMLHTTP.3.0");} catch(ex) {};
if (re != "nothing") {return re;}
else {return null;};
};
于 2012-09-17T08:50:35.823 回答