Link to home
Start Free TrialLog in
Avatar of blandyuk
blandyukFlag for United Kingdom of Great Britain and Northern Ireland

asked on

IE7 javascript createDocument issue :(

Hi Experts,

I have a problem where the below javascript wont work with IE7 :( I keep getting:
"Object doesn;t support this property or method"

Works fine in IE6 and Firefox. You'll see the alerts I've inserted to debug it. The problem line is:
"rt = document.implementation.createDocument('','',null);"

Any help will be great. Thanks.

Code:
---------------------------------------------------------------------
function SoapService()
{      
      //branch for Mozilla
      if (window.XMLHttpRequest)
      {
        this.XmlHttp = new XMLHttpRequest();
            if (this.XmlHttp.overrideMimeType) {
                  this.XmlHttp.overrideMimeType('text/xml');
            }

        this.Version=0;
    }
    // branch for IE6 / Windows ActiveX version
    else if (window.ActiveXObject)
    {
            this.XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            this.Version=1;
      }
      this.callService=_callService;
}
function _callService(func,params,async)
{
try{
      this.XmlHttp.open("POST", params[0], async);
      this.XmlHttp.setRequestHeader('Content-Type','text/xml; charset=UTF-8');
      this.XmlHttp.setRequestHeader('SOAPAction', '"'+params[1]+'"');
      var rt;
      if(async)
      {
            var XmlHttpAsync=this.XmlHttp;
            var VersionAsync=this.Version;
            this.XmlHttp.onreadystatechange =function()
            {
                  if(XmlHttpAsync.readyState != 4)return;
                  //alert(XmlHttpAsync.responseText);
                  if(VersionAsync==0)
                  {
                        rt = document.implementation.createDocument('','',null);
                        rt=XmlHttpAsync.responseXML;
                  }
                  else if(VersionAsync==1)
                  {
                        rt= XmlHttpAsync.responseXML.documentElement;
                  }
                  func(rt);
                  return true;

            }
      }
      this.XmlHttp.send(params[2]);
      if(!async)
      {
            //alert(this.XmlHttp.responseText);
            if(this.Version==0)
            {
                  alert('LOOK AT THIS!! START');
                  rt = document.implementation.createDocument('','',null);
                  alert('LOOK AT THIS!! MID');
                  rt=this.XmlHttp.responseXML;
                  alert('LOOK AT THIS!! FIN');
            }
            else if(this.Version==1)
            {
                  rt= this.XmlHttp.responseXML.documentElement;
            }
            func(rt);
            return true;
      }
}
catch(e){
            alert(e.description);
            return false;
}
}
function XmlRegExp(IrregExp)
{
      var strXml=IrregExp.toString();
      return strXml.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess IE7 now supports the window.XMLHttpRequest but still not the implementation so perhaps you need to modify


   if (window.XMLHttpRequest && document.implementation)
     {
        this.XmlHttp = new XMLHttpRequest();
          if (this.XmlHttp.overrideMimeType) {
               this.XmlHttp.overrideMimeType('text/xml');
          }

        this.Version=0;
    }
    // branch for IE6 / Windows ActiveX version or IE7
    else if (window.ActiveXObject)
    {
          this.XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          this.Version=1;
     }
or

   this.version = (document.implementation)?0:1;
   if (window.XMLHttpRequest)
     {
        this.XmlHttp = new XMLHttpRequest();
          if (this.XmlHttp.overrideMimeType) {
               this.XmlHttp.overrideMimeType('text/xml');
          }
    }
    // branch for IE6 / Windows ActiveX version
    else if (window.ActiveXObject)
    {
          this.XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
Avatar of blandyuk

ASKER

Ah! I was missing the "document.implementation.createDocument" out of the "if" statement. My new code is:

--------------------------------------

      if (document.implementation && document.implementation.createDocument)
      {
            this.XmlHttp = new XMLHttpRequest();
            if (this.XmlHttp.overrideMimeType) {
                  this.XmlHttp.overrideMimeType('text/xml');
            }
            this.Version=0;
      }
      else if (window.ActiveXObject)
      {
            this.XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            this.Version=1;
      }
      else
      {
            alert('Your browser can\'t handle this script');
            return;
      }

--------------------------------------

I did "Google" for ages with no success but sorted it now. Thanks mplungjan for that :)