我用javascript(for php)编写了一个ajax函数。它在WIN-XP机器中运行良好,但在WIN-2003中不起作用。
对于onclick事件,我正在调用fun_LeaveLength_JS_G
函数。在里面,我正在设置xmlhttp2.onreadystatechange=function()。这并没有执行。
我的功能如下:
function fun_LeaveLength_JS_G(dG1,dG2)
{
err2=true;
G_EmpIdFromJS=document.frmLeaveApp.txtG_EmpId.value;
G_PL_CountJS=document.frmLeaveApp.txt_PLCount.value;
PLAvailabe_JS= document.frmLeaveApp.PL_available.value;
CLAvailabe_JS=document.frmLeaveApp.CL_available.value;
LWPAvailabe_JS=document.frmLeaveApp.LWP_available.value;
MLAvailabe_JS=document.frmLeaveApp.ML_available.value;
COMPAvailabe_JS=document.frmLeaveApp.COMP_available.value;
FromHomeAvailabe_JS=document.frmLeaveApp.txt4mHome_available.value;
LeaveType_JS=document.frmLeaveApp.sltLeaveType.value;
alert(PLAvailabe_JS+" "+ CLAvailabe_JS +" "+ LWPAvailabe_JS +" "+ MLAvailabe_JS +" "+ COMPAvailabe_JS +" "+ FromHomeAvailabe_JS + " "+ LeaveType_JS);
if (dG1=="" || dG2=="")
{
return;
}
FromDate_G= dG1;
ToDate_G=dG2;
var d = new Date();
//if(str=="")
{
if (window.XMLHttpRequest)
{
xmlhttp2=new XMLHttpRequest();
}
else
{
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp2.onreadystatechange=function()
{
alert("Before response from the AJAX");
if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
{
document.frmLeaveApp.txtLeaveLeangth.value=xmlhttp2.responseText;
alert("in ajax fileError 2 is "+err2);
alert("Ajax result is : "+xmlhttp2.responseText);
//LeaveLength_JS=xmlhttp2.responseText();
if(xmlhttp2.responseText==1)
{
err2=true;
alert("when ajax result is 1 error 2 is "+err2);
LeaveLength_JS=xmlhttp2.responseText();
}
if(xmlhttp2.responseText==0)
{
err2=false;// allow to apply leave
alert("when ajax result is 0 error 2 is "+err2);
}
else
{
err2=true;
alert("when ajax result is other then error 2 is "+err2);
Alert("This is developer error. Please Inform to System admin");
}
}
}
xmlhttp2.open("GET","http://localhost/MyProject/LeaveLength_Ajax.php?_Get_FromDate="+FromDate_G+"&_Get_ToDate="+ToDate_G+"&PLAvailabe_JS="+PLAvailabe_JS +"&CLAvailabe_JS="+CLAvailabe_JS +"&LWPAvailabe_JS="+LWPAvailabe_JS+"&MLAvailabe_JS="+MLAvailabe_JS+"&COMPAvailabe_JS="+COMPAvailabe_JS+"&FromHomeAvailabe_JS="+FromHomeAvailabe_JS +"&LeaveType_JS="+LeaveType_JS,true);
xmlhttp2.send();
}
alert("At the end Error 2 is "+err2);
}
哪里出了问题?我需要包含或安装任何支持软件吗?
我认为这里的问题与操作系统无关。当您在Win2003上尝试此操作时,您在测试该机器时是否真的?因为您正试图查询localhost
,这意味着您查询的是本地机器,而不是网络地址。
尝试更改此行:
xmlhttp2.open("GET","http://localhost/...")
类似的东西:
xmlhttp2.open("GET","http://<server name or IP>/...")
在这里运行良好。你正在使用IE6?