リンクをクリックすると ajax が正常に実行されるようにページにリンクがありますが、このリンクがクリックされたときに複数の ajax 呼び出しを実行し、同じクエリ文字列を別のページに渡すにはどうすればよいですか?
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 に答える