javascripthtmlfirefoxxmlhttprequestactivexobject

XMLHttpRequest().Open is not a function in Firefox, but it works in Chrome


I have the function below but when I try to run it in Firefox, I get the error "xmlhttp.Open is not a function". This does not happen in Google Chrome, however

Have I missed some code converting from the ActiveXObject? The PAGE parameter is set and works for the ActiveXObject in Internet Explorer

function broker(PAGE, PARAMARR, STARTPARAM) {
  var postdata = getPostData();
  var ua = navigator.userAgent;
  var msie = ua.indexOf('MSIE ');
  //var xmlhttp =null;
  if (msie != -1) {
    xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
    xmlhttp.Open('POST', PAGE, false);
    xmlhttp.setRequestHeader(
      'Content-Type',
      'application/x-www-form-urlencoded; charset=UTF-8'
    );
  } else {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.Open('POST', PAGE, false);
    xmlhttp.setRequestHeader(
      'Content-Type',
      'application/x-www-form-urlencoded; charset=UTF-8'
    );
  }
  var paramno, param;
  for (paramno = STARTPARAM; paramno < PARAMARR.length; paramno++) {
    param = PARAMARR[paramno];
    if (param == void 0) param = '';
    if (param === true) param = -1;
    if (param === false) param = 0;
    postdata = postdata + '&Parameter=' + encodeURIComponent(param);
  }
  xmlhttp.setRequestHeader('Content-Length', postdata.length);
  xmlhttp.send(postdata);
  var response = new String(xmlhttp.responseText);
  var brkmsg = getMessage(response);
  return brkmsg;
}

Chrome: Netscape mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/47.0.2526.106 safari/537.36

Firefox: Netscape mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0

IE11: Netscape mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; slcc2; .net clr 2.0.50727; .net clr 3.5.30729; .net clr 3.0.30729; media center pc 6.0; .net4.0c; .net4.0e; infopath.3; rv:11.0) like gecko)

IE8 (Compatability Mode): Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; Trident/4.0; .NET CLR 3.0.4506.2152; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.2)


Solution

  • Seems to be a typo. Write "open" in lower case!