Kod
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
if (window.ActiveXObject) {
try {
XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
} catch (e) {alert("Sorry, but I couldn't create an XMLHttpRequest");xmlHttp=false;}
}
}
return xmlHttp;
}
function loadXmlHttpRequestObject(url) {
if (xmlHttp) {
try {
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try {
var outMsg = xmlHttp.responseText;
document.getElementById("updateArea").innerHTML = outMsg;
} catch(e) {
alert("There was a problem with loading the request: " + e.toString());
}
} else {alert("There was a problem with the request: " + xmlHttp.status);}
} else {/* Ponawia ponownie żadanie */}
};
xmlHttp.send(null);
} catch (e) {alert("Sorry, but I couldn't connecting server:\n" + e.toString());}
}
}
window.onload = initAll;
function initAll() {
document.getElementById("o_nas").onclick = getNewFile;
}
function getNewFile() {
loadXmlHttpRequestObject(this.href);
return false;
}
function createXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
if (window.ActiveXObject) {
try {
XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
} catch (e) {alert("Sorry, but I couldn't create an XMLHttpRequest");xmlHttp=false;}
}
}
return xmlHttp;
}
function loadXmlHttpRequestObject(url) {
if (xmlHttp) {
try {
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try {
var outMsg = xmlHttp.responseText;
document.getElementById("updateArea").innerHTML = outMsg;
} catch(e) {
alert("There was a problem with loading the request: " + e.toString());
}
} else {alert("There was a problem with the request: " + xmlHttp.status);}
} else {/* Ponawia ponownie żadanie */}
};
xmlHttp.send(null);
} catch (e) {alert("Sorry, but I couldn't connecting server:\n" + e.toString());}
}
}
window.onload = initAll;
function initAll() {
document.getElementById("o_nas").onclick = getNewFile;
}
function getNewFile() {
loadXmlHttpRequestObject(this.href);
return false;
}
Chodzi o to by zmienną outMsg wyciągnąć jako globalną, czy jest to wogule możliwie? Problem leży przy "xmlHttp.onreadystatechange".