私のテストでこれを試してみてください。ほとんどのブラウザで動作します
var responseText=function(e,doing){
if (e.readyState== 4) {
if(doing)doing(e);
return(e.responseText);
};
if (e.readyState == 200) {
if(doing)doing(e);
return(e.responseText);
};
return false;
};
function loadXMLPostDocf(url,method,posData,uploadProgress,uploadComplete,uploadFailed,uploadCanceled,statechange,CallBackOnSend) {
var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest && checkVersion()) {
pos = new XMLHttpRequest();
pos.open(method, url, true);
//pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if(statechange!=''){pos.onreadystatechange = statechange;};
try{
if(uploadProgress!='')if(pos.upload){
pos.upload.addEventListener("progress", uploadProgress, true);
}else{
pos.addEventListener("progress", uploadProgress, true);
}
if(uploadComplete!='')pos.addEventListener("load", uploadComplete, false);
if(uploadFailed!='')pos.addEventListener("error", uploadFailed, false);
if(uploadCanceled!='')pos.addEventListener("abort", uploadCanceled, false);
}catch(e){
}
pos.send(posData);
if(CallBackOnSend)CallBackOnSend(pos);
//console.log(pos.abort());
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
for (var i=0; i < arrSignatures.length; i++) {
try {
pos = new ActiveXObject(arrSignatures[i]);
} catch (oError) {
//ignore
};
};
if (pos) {
pos.open(method, url, false);
//pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if(!statechange){pos.onreadystatechange = statechange;};
if(!uploadComplete){pos.onreadystatechange = uploadComplete;};
// if(uploadProgress!='')pos.upload.addEventListener("progress", uploadProgress, true);
//if(uploadComplete!='')pos.addEventListener("load", uploadComplete, false);
//if(uploadFailed!='')pos.addEventListener("error", uploadFailed, false);
//if(uploadCanceled!='')pos.addEventListener("abort", uploadCanceled, false);
pos.send(posData);
if(CallBackOnSend)CallBackOnSend(pos);
};
};
return(pos);
};
サンプル:
var complete=function(e){
var Body=responseText(e.target);
console.log(Body);
};
var uploadProgress=function(evt){
};
var uploadComplete=function(evt){
if(evt.target.status==200 || evt.target.status==304){
var Body=responseText(evt.target);
console.log(Body);
}else{
return false;
};
};
var uploadFailed=function(evt){
};
var uploadCanceled=function(evt){
};
var CallBackOnSend=function(evt){
};
loadXMLPostDocf("http://domain.com/index.php","GET",null,uploadProgress,uploadComplete,uploadFailed,uploadCanceled,complete,CallBackOnSend);