0
我想作爲參數傳遞一個通用函數爲onreadystate
function
,我該怎麼做,並訪問xmlhttpobj
? 類似的東西:JavaScript AJAX回調函數作爲參數
function xmlHttp(target, xml, readyfunc) {
if (window.XMLHttpRequest) {
httpObj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
httpObj = new ActiveXObject("Microsoft.XMLHTTP");
}
if (httpObj) {
httpObj.onreadystatechange = readyfunc;
httpObj.open("POST", target, true);
httpObj.send(xml);
}
}
function Run (Place){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
//do a lot of things in "Place"
}
你錯過了'var':你可以調用XMLHTTP的功能是這樣的。不要試圖讓它成爲全球。 – Bergi