注册 登录
编程论坛 jQuery论坛

[求助]ajax兼容问题

我才是阿军啊 发布于 2007-06-26 22:16, 1585 次点击

ajax兼容问题,大家帮我看看,我的在ff和opera下不惯用啊,急死人了,是不是js不规范,大家帮我修正下,谢谢.


<!--
var xmlHttp;
function GetNowTime(){
var date = new Date(); //ÈÕÆÚ¶ÔÏó
var now = \"\";
now = date.getFullYear()+\"y\";
now = now + (date.getMonth()+1)+\"m\";
now = now + date.getDate()+\"d\";
now = now + date.getHours()+\"h\";
now = now + date.getMinutes()+\"m\";
now = now + date.getSeconds()+\"s\";
return now;
}
function CleanLoading(){
document.getElementById('loading').innerHTML = \"\";
}
function createXMLHttpRequest(){
if (typeof XMLHttpRequest == \"undefined\"){
  var xmlHttpVersions = [ \"MSXML2.XMLHttp.5.0\",\"MSXML2.XMLHttp.4.0\",\"MSXML2.XMLHttp.3.0\",\"MSXML2.XMLHttp\",\"Microsoft.XMLHttp\"];
  for(var i = 0;i < xmlHttpVersions.Length;i++){
   try{
    return new ActiveXObject(xmlHttpVersions[i]);
   }
   catch(oError){
    //there is nothing to do with
   }
  }
  throw new error(\"there whould be no error at all!\");
}
else if (window.XMLHttpRequest){
  return new XMLHttpRequest();
}
}

if (ajax == null && typeof XMLHttpRequest != 'undefined')
{
  ajax = new XMLHttpRequest();
}

return ajax;
}
function starRequest(object,VerID){
var url;
switch(object){
  case 1: { //Â¥ÅÌÐÅÏ¢,ÏîÄ¿¸Å¿ö
   url = \"/ajax/gaikuang.php?VerID=\"+VerID+\"&time=\"+GetNowTime();//¼ÓÈëʱ¼ä´Á,±ÜÃâä¯ÀÀÆ÷»º´æ
   break;
  }
  case 2: { //Â¥ÅÌÐÅÏ¢,ÏîÄ¿¸Å¿ö
   url = \"/ajax/gaikuang.php?VerID=\"+VerID+\"&time=\"+GetNowTime();
   break;
  }
}
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open(\"get\",url,true);
  xmlHttp.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");
xmlHttp.send(null);
}
function handleStateChange(){
document.getElementById('loading').innerHTML = \"<img src='/images/loading3.gif'/>Êý¾Ý¼ÓÔØÖÐ...\";
if(xmlHttp.readyState == 4){
  if(xmlHttp.status == 200){
   document.getElementById('main').innerHTML = xmlHttp.responseText;
  }
}
setTimeout(\"CleanLoading()\",500);
}
-->

0 回复
1