一段ajax代码,小弟不才研究了很久都不能在firefox运行,代码如下:<SCRIPT language="JavaScript">
function CheckInput()        

 if (document.form.xh.value == "")        
  {        
    alert("学号不能为空!");        
    document.form.xh.focus();        
    return false;        
  }   
  if (document.form.stuname.value == "")        
  {        
    alert("姓名不能为空!");        
    document.form.stuname.focus();        
    return false;        
  }
  var xh = document.getElementById("xh").value;
  var stuname = document.getElementById("stuname").value;
  var team = document.getElementById("team").value;
  GetResult(xh,stuname,team);      
 }
 function GetResult(xh,stuname,team)
{
     var xh = document.getElementById("xh").value;
  var stuname = document.getElementById("stuname").value;
  var team = document.getElementById("team").value;
    var oBao = new ActiveXObject("Microsoft.XMLHTTP");
    oBao.open("POST","search.asp?xh="+escape(xh)+"&stuname="+escape(stuname)+"&team="+escape(team),false);
    oBao.send();
var backstring=unescape(oBao.responseText);
document.all.msg.innerHTML =backstring;
}
//-->
</script> 在ie上运行这段代码均没任何问题,代码的目的是通过输入学号和姓名达到查询分数的功能,但在firefox下按“查询”按钮均无任何反应,求各位大哥赐教,如何修改这段代码才能实现在ie和firefox下均能查询?

解决方案 »

  1.   

    var oBao = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
      

  2.   

    http://blog.csdn.net/chinmo/archive/2008/02/17/2100311.aspx
    看看JS对在IE和FF的区别啊
      

  3.   

    chinmo的意思就是说无法兼容firefox了?
      

  4.   

    第一点:document.all.msg.innerHTML =backstring; 
    document.all
    Firefox可以兼容document.all, 
    但会生成一条警告。可以用getElementById("*") 或者 
    getElementByTagName("*)来代替
    不过对于document.all.length等属性,则完全不兼容。
    第二点: Form对象 现有问题:
    现有代码这获得form对象通过document.forms("formName"),这样使用在IE 能接受,MF 
    不能。
    解决方法:
    改用 作为下标运算。改为document.forms["formName"]
    备注
    上述的改用 
    作为下标运算中的formName是id而name
      

  5.   

    1.2 HTML对象 
    现有问题:
    在 IE 中,HTML 对象的 ID 可以作为 
    document 的下属对象变量名直接使用。在 MF 
    中不能。
    document.all("itemName")或者document.all("itemId")
    解决方法:
    使用对象ID作为对象变量名
    document.getElementById("itemId")
    备注
    document.all是IE自定义的方法,所以请大家尽量不使用。
    还有一种方式,在IE和MF都可以使用
    var 
    f = document.forms["formName "];
    var o = f. itemId;
      

  6.   

    我建议是你使用alert(错误)
    这样的语句来逐句检查看看程序到哪就执行不了,你才可以找出相对应的对策修改
      

  7.   

    可是这段代码没有用document.all 吧??还有,,document.form也是一样。我这代码的功能是搜索对应的表格输出要满足表中学号和姓名的所有成绩。
      

  8.   


    问题应该出在这里:    var oBao = new ActiveXObject("Microsoft.XMLHTTP");
        oBao.open("POST","search.asp?xh="+escape(xh)+"&stuname="+escape(stuname)+"&team="+escape(team),false);
        oBao.send();
    var backstring=unescape(oBao.responseText); 不知道如何改?
      

  9.   

    document.all.msg.innerHTML =backstring; 
    document.form.stuname.value我不知道你这些是什么
      

  10.   

    不是应该出在这儿是你要用alert('错误')去检测
    alert(backstring)看看这个有值没?
      

  11.   

    是post没有值得话
    试试这个方法
    http_request.open('POST', url, true);
                    http_request.setRequestHeader("Content-length", postdata.length);
                    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    http_request.send(postdata);
    设置一个header
      

  12.   

    我估计是你post没有起作用,在FF里你如果没有设置一个header是不行的
      

  13.   

    楼上的意思是这段代码放在头部吗?对阿,我的这段代码一直都是放在<header></header>的阿。不是body阿
      

  14.   

    那位高手大哥帮忙改一下来支持firefox输出搜索的结果阿??
      

  15.   

    晕不是放在 <header> </header>
    var team = document.getElementById("team").value; 
        var oBao = new ActiveXObject("Microsoft.XMLHTTP"); 
        oBao.open("POST","search.asp?xh="+escape(xh)+"&stuname="+escape(stuname)+"&team="+escape(team),false); 
        oBao.send(); 你没发现你这个
    和我
    http_request.open('POST', url, true); 
                    http_request.setRequestHeader("Content-length", postdata.length); 
                    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
                    http_request.send(postdata); 这个对比下少了什么吗?