function check_sap()
{
var xmlhttp
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
var URL
URL="check_sap.asp?scode="+sapCode;
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
alert(xmlhttp.readyState);
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
}
}
//alert(check_num);
return false;
}
红色部分应该是弹出0或者1、2、3、4啊,但我的什么都没有,这么回事
{
var xmlhttp
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
var URL
URL="check_sap.asp?scode="+sapCode;
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
alert(xmlhttp.readyState);
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
}
}
//alert(check_num);
return false;
}
红色部分应该是弹出0或者1、2、3、4啊,但我的什么都没有,这么回事
xmlHttp.send(null);
alert(xmlhttp.readyState);
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
}
}
你要放在回调函数里面呀!!!!!!!!!
改成
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function(){
alert(xmlhttp.readyState);
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
}
}
}
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
var URL
URL="check_sap.asp?scode="+sapCode;
xmlhttp.open("GET",URL,true);
xmlhttp.send(null);
xmlhttp.onstatereadychange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
if(check_num=="1")
{
alert("SAP Code had been existed!");
return false;
}
}
}
}
//alert(check_num);
return false;
这是现在的代码,我都快搞疯了
前面不用看,就出在if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
if(check_num=="1")
{
alert("SAP Code had been existed!");
return false;
}
}
}
这部分没有弹出来,我搞了一天了,初学ajax,有点郁闷
{
//alert(document.getElementById("sap_code").value);
var sapCode = document.getElementById("sap_code").value;
var check_num
var re = /^\d{8}$/;
if(!re.test(sapCode)){
alert("SAP Code必须为8位数字!");
return false;
}
if(re.test(sapCode))
{
var xmlhttp
if(window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
var URL
URL="check_sap.asp?scode="+sapCode;
xmlhttp.open("GET",URL,true);
xmlhttp.send(null);
xmlhttp.onstatereadychange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var check_num=xmlhttp.responseText;
alert(check_num);
if(check_num=="1")
{
alert("SAP Code had been existed!");
return false;
}
}
}
}
//alert(check_num);
return false;
}
return false;
}
试试先
后面加了alert("ggg");也没有弹出来
是直接输入http://xxx.com/check_sap.asp?scode=12345678吗?
之前加入 alert(xmlhttp.readyState),如果程序运行到这里正常应该会又1、2、3、4的提示
如果没有。就在前面的程序找错误,如果有就在
if(xmlhttp.status==200){ 之前加入alert(xml.status)测试一下服务器返回的状态吗。。
如果是500代表ASP程序错误,如果是200则代表没错就继续测试下面的
之前可以显示,放在之后不能显示,那就应该说明是这里出错了啊?
xmlHttp.onreadystatechange=function(){ 是这样?
还是xmlhttp.onreadystatechange=function(){ ?