2

我只有在ie8才有这个问题

这是我的 javascript 代码

var bustcacheparameter="" ;

function createRequestObject(){
    try {
        xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    }   catch(e)    {
        alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
    };
    return xmlhttp;
};
function ajaxpage(url, containerid){
    var page_request = createRequestObject();

    if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', url+bustcacheparameter, true)
    page_request.send(null)

    page_request.onreadystatechange=function(){
        loadpage(page_request, containerid)
    }
}
function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
        document.getElementById(containerid).innerHTML=page_request.responseText;
    };
}
function LoadMonth(month, year) {
    ajaxpage("calendar.php?month="+month+"&year="+year, "Calendar")
}
LoadMonth();

我用ie测试仪知道这个错误 line : 26 char : 6 unknown runtime error

4

1 回答 1

1

试试这个 ; 它用于兼容性问题,即

我希望它有帮助

AJAX 支持

 function createXMLHttpRequest()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function getModIndex(val) {
    var divEle = "IndexDiv" + val;
    var request = createXMLHttpRequest();

    if ( !request ) { 
    alert( request )
    return false
    }

    var callback = function( oXML ) {
    document.getElementById( divEle ).innerHTML = oXML.responseText;
    }

    request.connect(
    '../ajax/ajax-GetIndex.php',
    'POST',
    'id=' + val,
    callback
    );
}
于 2012-05-30T12:11:00.357 回答