+ -
当前位置:首页 → 问答吧 → 帮忙看看这段ajax怎么不兼容火狐浏览器

帮忙看看这段ajax怎么不兼容火狐浏览器

时间:2011-03-30

来源:互联网

function getxmlhttprequest(){
  if(window.XMLHttpRequest){ //Mozilla 
  XMLHttpReq=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  try{
  XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
  try{
  XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){}
  }
  }
return XMLHttpReq;
}



function getcodevalue()
{

  if(xmlhttp.readyState == 4)
  {

  var response = xmlhttp.responseText;
response=response.replace(/\s/g, "");
if(response=='')
{alert('对不起,您填写的资料有误或者刚咨询过,暂时不能提交!');document.getElementById('uname').value='',document.getElementById('phone').value='',document.getElementById('xm').value='';}
else
{alert('谢谢您的咨询,我们将尽快跟您电话联系!');document.getElementById('uname').value='',document.getElementById('phone').value='',document.getElementById('xm').value='';}
 
 
  }
}

function addxm()
{  
  var uname,phone,xm;
  uname=document.getElementById("uname").value;
  phone=document.getElementById('phone').value;
  xm=document.getElementById('xm').value;
if((uname=='')||(phone=='')||(xm=='')){alert('请填写完整的内容');document.getElementById('uname').focus();}
else
{

xmlhttp = getxmlhttprequest();

if(xmlhttp == null)
{
alert("浏览器不支持xmlhttprequest!");
return;
}

var url = "/zx.php?username="+uname+"&phone="+phone+"&xm="+xm+"&j="+ Math.round(Math.random()*100)+"&add=ok&curl="+location.href; 

xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange=getcodevalue; //指定响应的函数
xmlhttp.send(null); //发送请求
}
}

function hidexm()
{
document.getElementById('xmform').style.display='none';
}

作者: zhagli535242428   发布时间: 2011-03-30

JScript code

function getxmlhttprequest(){
  var XMLHttpReq;//局部变量
  if(window.XMLHttpRequest){ //Mozilla 
  XMLHttpReq=new XMLHttpRequest();
  }
  else if(window.ActiveXObject){
  try{
  XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
  try{
  XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){}
  }
  }
return XMLHttpReq;
}



function getcodevalue()
{

  if(xmlhttp.readyState == 4)
  {

  var response = xmlhttp.responseText;
response=response.replace(/\s/g, "");
if(response=='')
{alert('对不起,您填写的资料有误或者刚咨询过,暂时不能提交!');document.getElementById('uname').value='',document.getElementById('phone').value='',document.getElementById('xm').value='';}
else
{alert('谢谢您的咨询,我们将尽快跟您电话联系!');document.getElementById('uname').value='',document.getElementById('phone').value='',document.getElementById('xm').value='';}
 
 
  }
}

//这个不能少,不然上面的函数的xmlhttp就没有定义
var xmlhttp;
function addxm()
{  
  var uname,phone,xm;
  uname=document.getElementById("uname").value;
  phone=document.getElementById('phone').value;
  xm=document.getElementById('xm').value;
if((uname=='')||(phone=='')||(xm=='')){alert('请填写完整的内容');document.getElementById('uname').focus();}
else
{

xmlhttp = getxmlhttprequest();

if(xmlhttp == null)
{
alert("浏览器不支持xmlhttprequest!");
return;
}

var url = "/zx.php?username="+uname+"&phone="+phone+"&xm="+xm+"&j="+ Math.round(Math.random()*100)+"&add=ok&curl="+location.href; 

xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange=getcodevalue; //指定响应的函数
xmlhttp.send(null); //发送请求
}
}

function hidexm()
{
document.getElementById('xmform').style.display='none';
}

作者: IBM_hoojo   发布时间: 2011-03-30