0
進出口新的阿賈克斯..請多多包涵。我的代碼如下:無法設置全局變量的函數內阿賈克斯
功能checkempid(){
var status;
xmlHttp=GetXmlHttpObject();
var urlemp="postemployee";
urlemp=urlemp+"?employeeId="+document.PostAvailableBench.employeeId.value;
xmlHttp.onreadystatechange=stateChangedemp ;
xmlHttp.open("GET",urlemp,true);
xmlHttp.send(null);
var showdata;
function stateChangedemp(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
showdata = xmlHttp.responseText;
alert(showdata);
if(showdata.trim()=="available"){
alert("inside if");
saveReportFinished(true);
}
else{
alert("inside else");
saveReportFinished(false);
}
}
}
function saveReportFinished(success) {
if (success == true)
{
status = true;
}
else
{
status = false;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
return status;
}
我試圖設置'狀態'這是'saveReportFinished'函數內的全局變量,並試圖通過使用'返回狀態'返回狀態..但它只返回初始值,並且不返回值saveReportFinished函數。如果有人能幫助我,我會很高興。提前謝謝您!