var xmlHttp;         //创建的一个全局的变量
function createxmlhttp(){
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
};  //给这个全局附直
window.onload = function(){
createxmlhttp();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4)
alert(xmlHttp.responseText)
};
xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true) 
xmlHttp.send(null);
};
//在这个以上的地方   ie  ff 下都是对的了  都可以alert出来数据
//在这个以下的地方 Set方法绑定在一个按纽上    ff下可以弹出数据(不管安多少次)  ie却不行   怎么办了?
function Set(){
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4)
alert(xmlHttp.responseText)
};
xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true) 
xmlHttp.send(null)
};

解决方案 »

  1.   

    添加个高亮色
            var xmlHttp;        //创建的一个全局的变量
    function createxmlhttp(){
    if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
    }
    };  //给这个全局附直
    window.onload = function(){
    createxmlhttp();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState == 4)
    alert(xmlHttp.responseText)
    };
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true)
    xmlHttp.send(null);
    };
    //在这个以上的地方  ie  ff 下都是对的了  都可以alert出来数据
    //在这个以下的地方 Set方法绑定在一个按纽上    ff下可以弹出数据(不管安多少次)  ie却不行  怎么办了?
    function Set(){
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState == 4)
    alert(xmlHttp.responseText)
    };
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true)
    xmlHttp.send(null)
    }; 
      

  2.   

    LZ是怎么绑定Set函数的?贴下你的html代码
      

  3.   

    function SetV(){
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState == 4)
    alert(xmlHttp.responseText)
    };
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true)
    xmlHttp.send(null)
    }; set 可能会与关键字冲突,改一个,还有这个函数仅仅定义好象没有被调用呢,试看...
      

  4.   

    <input value="按牛" type="button" onclick="Set()" />
    html页面就这么一个元素了
    ie下不行  确切的说是ie6(别的版本不知道)
    ff  chrome都是可以的
    -------------------------------------------------
    换成其他的名字也不行  如 换成 change为什么ff  chrome下却可以了
      

  5.   

    input不需要关闭标签
    <input>
    ...
      

  6.   

    function Set(){
    alert("LZ先把函数换成这个看看可不可以!");
    }
      

  7.   

    function Set(){ 
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true);
    xmlHttp.send(null); 
    }这样呢?
      

  8.   

    function Set(){
    alert('xbb')
    xmlHttp.onreadystatechange=function(){
    alert('xxxx')
    if(xmlHttp.readyState == 4)
    alert(xmlHttp.responseText)
    };
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true) 
    xmlHttp.send(null)
    alert('xx')
    };
    里面就 alert('xxxx')不能执行
      

  9.   

    实在不行,LZ这样吧
    function Set(){ 
    createxmlhttp();
    xmlHttp.onreadystatechange=function(){ 
    if(xmlHttp.readyState == 4) 
    alert(xmlHttp.responseText); 
    };
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true); 
    xmlHttp.send(null); 
    }
      

  10.   

    恩  这是每次都重新创建一次xmlHttp吧
    这样多不好啊  哈哈
    听说是缓存的问题
    不过还是没试出来
      

  11.   

    可能是受上一次请求的影响,这样吧,在调用的时候强制停止上次请求function Set(){ 
    xmlHttp.abort();//停止当前请求
    xmlHttp.onreadystatechange=function(){ 
    if(xmlHttp.readyState == 4) 
    alert(xmlHttp.responseText); 
    }; 
    xmlHttp.open("GET","GetDataService?method=getProvinceByCountry&countryID=86",true); 
    xmlHttp.send(null); 
    }
      

  12.   

    有缓存的话,在url后面加个时间戳...
      

  13.   

    不是缓存的问题我刚刚跟踪了一下状态,在open之前,状态为4,open之后,状态为1,但是后面就没有改变过了通过xmlHttp.abort();将状态置为0,open之后为1,send后,依次2,3,4,一切正常
    其实LZ加上这句也可以,而且可以防止重复提交呢,呵呵可能是浏览器的BUG吧