javascript - Problems inheriting XMLHttpRequest / ActiveXObject classes -


i have following javascript class:

var server = function(onerror) {     /* public as, onerror; */      var that, key, headers;      this.__construct = function()     {         = this;          that.as = false;         that.onerror = onerror;         that.resetheaders();          onerror = null;          // here try call parent constructor (it seems can't).          if(window.xmlhttprequest)             that.xmlhttprequest();         else             that.activexobject('microsoft.xmlhttp');     }      this.request = function(file, postdata, function)     {         var method, headerkey;          if(postdata == null)             method = 'get';         else             method = 'post';          try         {             that.open(method, file, that.as);              /* each request sets x-requested-with xmlhttprequest default.                if postdata given, treat it's content type form.*/              that.setrequestheader('x-requested-with', 'xmlhttprequest');              if(postdata != null)                 that.setrequestheader('content-type', 'application/x-www-form-urlencoded');              for(headerkey = 0; headerkey < headers.length; headerkey++)                 that.setrequestheader(headers[ headerkey ].name, headers[ headerkey ].value);              if(function != null)                 that.onreadystatechange = function()                 {                     if(that.readystate == 4 && that.status == 200)                         function.call();                 }              that.send(postdata);         }         catch(exception)         {             if(that.onerror != null)                 that.onerror(exception);         }     }      this.addheader = function(name, value)     {         headers[ key ] = {};         headers[ key ].name = name;         headers[ key ].value = value;          key++;     }      this.resetheaders = function()     {         headers = [];         key = 0;     }      this.__construct(); }  if(window.xmlhttprequest)     server.prototype = new xmlhttprequest(); else     server.prototype = new activexobject('microsoft.xmlhttp');  server.prototype.constructor = server; 

where make inheritance depending on state of window.xmlhttprequest var. in __construct method re-check again call parent constructor.

i don't know if correct form, tell me what's wrong in here. way, when check console in chrome following exception: "uncaught typeerror: object [object object] has no method 'xmlhttprequest'", assume not identifying correct reference, however, can see properties / methods present when put "." in console, can't access internal / external way (this commenting parent constructor condition). thank you, i'll wait replies.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -