日期:2014-05-16  浏览次数:20695 次

ajax不进onreadystatechange - Web 开发 / Ajax
function a() {

var show = document.getElementById("ceshi") ;
var ajax = InitAjax() ;
var url = "http://localhost:8080/web/provideBuy.html?method=provideBuyListByUserIdFind" ;
ajax.open("GET" ,url,true) ;
var a = ajax.readyState ;
alert(a) ;
//var b = ajax.status ;
//alert(b) ;
ajax.onreadystatechange = function (){
if(ajax.readyState==4 && ajax.status==200){
show.innerHTML = ajax.responsText ;
}
if(ajax.readyState==1){
show.innerHTML = "数据提交中" ;
}
}
}
function InitAjax()
{
 var ajax=false;
 try {
  ajax = new ActiveXObject("Msxml2.XMLHTTP");
alert("A") ;
 }
  catch (e) {
  try {
   ajax = new ActiveXObject("Microsoft.XMLHTTP");
alert("B") ;
   }
catch (E) {
   ajax = false;
   }
 }
 if (!ajax && typeof XMLHttpRequest!='undefined') {
  ajax = new XMLHttpRequest();
alert("C") ;
 }
 return ajax;
}

里面的URL是可用的,直接放到地址栏里测试没问题,但是ajax.readyState返回值是1,不知任何是好了

------解决方案--------------------
晕,你都没send.......

JScript code
function a() {  

var show = document.getElementById("ceshi") ;
var ajax = InitAjax() ;
var url = "http://localhost:8080/web/provideBuy.html?method=provideBuyListByUserIdFind" ;
ajax.open("GET" ,url,true) ;
var a = ajax.readyState ;
alert(a) ;
//var b = ajax.status ;
//alert(b) ;
ajax.onreadystatechange = function (){
if(ajax.readyState==4 && ajax.status==200){
show.innerHTML = ajax.responsText ;
}
if(ajax.readyState==1){
show.innerHTML = "数据提交中" ;
}
}

//============
ajax.send(null);
}