This is a migrated thread and some comments may be shown as answers.

What happens if XmlHttpRequest is not available

4 Answers 174 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
surfer
Top achievements
Rank 1
surfer asked on 09 May 2007, 11:50 AM
Does anyone know if MS AJAX supports legacy browsers without the XmlHttpRequest object? Or if it works in a setup where end-users have set the "Script ActiveX controls marked safe for scripting" option to Disabled? There is a very old <iframe> trick to request remote hosts in XmlHttpRequest is not available, will this work?

And if it doesn't is rad AjaxManager able to extend it so it does provide support for that?

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 May 2007, 01:34 PM
Hello surfer,

Currently MS AJAX does not support this and we do not have any plans to support this also - you can check MicrosoftAjax.debug.js located in ASP.NET AJAX installation folder how this actually is created:
if (!window.XMLHttpRequest) { 
    window.XMLHttpRequest = function window$XMLHttpRequest() { 
        var progIDs = [ 'Msxml2.XMLHTTP''Microsoft.XMLHTTP' ]; 
         
        for (var i = 0; i < progIDs.length; i++) { 
            try { 
                var xmlHttp = new ActiveXObject(progIDs[i]); 
                return xmlHttp; 
            } 
            catch (ex) { 
            } 
        } 
         
        return null
    } 

You do not need to worry about "Script ActiveX controls marked safe for scripting" - in IE7 XmlHttpRequest is native object.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
surfer
Top achievements
Rank 1
answered on 09 May 2007, 03:16 PM
Yep, but in many corporate/educational settings, people are still using IE 5.5 and 6 and have very tight security. The fallback would be a realy good feature!

Anyway, Fabio lead me to this wonderful javascript workaround the problem suggested by andado in the following forum thread.
http://www.telerik.com/community/forums/thread/b311D-cmdkk.aspx

I haven't had the time to test it yet, but looks exactly what I've been looking for! Maybe you can add this XmlHttpRequest emulation to the radAjaxManager "Prometheus" product and have a property to turn it on, e.g. EnableLegacyBrowserSupport, or EnableXmlHttpRequestEmulation...
Could be a very nice feature that outmatches the UpdatePanel - support for legacy browsers is in huge demand in some corporate settings.

if (window.XMLHttpRequest == "undefined"
var XMLHttpRequest = function() 
        { 
         this.method = "POST"
         this.url = null
         this.async = true
         this.iframe = null
         this.responseText = null
         this.header = new Object(); 
         this.container = document.body; 
        } 
 
        XMLHttpRequest.prototype.open = function(method, url, async) 
        {       
         this.method = method; 
         this.url = url; 
         this.async = async; 
         this.readyState = 0; 
 
         this.iframe = document.getElementById("CallbackIframe");  // your hidden iframe 
         this.id = this.iframe.id; 
         this.setRequestHeader("___xmlhttp""iframe"); 
        } 
 
        XMLHttpRequest.prototype.setRequestHeader = function(name, value) 
        { 
          this.header[name] = value; 
        } 
 
        XMLHttpRequest.prototype.send = function(data) 
        { 
          this.iframe._xmlhttp = this
          this.iframe._xmlhttp._fix = -1; 
          this.iframe._xmlhttp.responseText = null
          this.iframe.onreadystatechange = this._onreadystatechange; 
          this.iframe.src =this.url; 
        } 
 
        XMLHttpRequest.prototype._onreadystatechange = function() 
        { 
 
           this._xmlhttp._fix++; 
         
          if(this._xmlhttp._fix < 1) 
            return
         
           if(this._xmlhttp._fix == 1) 
      { 
            this._xmlhttp.readyState = 1; 
           } 
           else if(this._xmlhttp._fix > 1) 
           { 
            switch(this.readyState.toString()) 
            { 
              case "loading"
               this._xmlhttp.readyState = 2; 
                break
 
        case "interactive"
               this._xmlhttp.readyState = 3; 
                break
 
        case "complete"
 
              if(window.frames[this.id].document.body.childNodes[0].outerText) 
              { 
                this._xmlhttp.responseText = window.frames[this.id].document.body.childNodes[0].outerText; 
              } 
              else 
              { 
                 this._xmlhttp.responseText = ""
              } 
               this.onreadystatechange = function(){} 
               this._xmlhttp.readyState = 4; 
               break
            } 
           } 
         
         if(typeof(this._xmlhttp.onreadystatechange) == "function"
           this._xmlhttp.onreadystatechange(); 
        } 

0
Hristo Deshev
Telerik team
answered on 14 May 2007, 12:24 PM
Hello surfer,

I am afraid this is not such a good idea. Prometheus relies on ASP.NET AJAX to do the heavy lifting related to XMLHttpRequest handling. I don't think we can plug an IFRAME-based implementation in there.

If I remember correctly the original Atlas CTP releases had some support for performing async requests using a hidden IFRAME, but that feature has been dropped. I assume the Microsoft guys don't want to support such a hack on all browsers.

Kind regards,
Hristo Deshev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
surfer
Top achievements
Rank 1
answered on 15 May 2007, 09:34 AM
Fair enough - I completely understand your reasons. It would be very cool if we could support legacy browsers with just switching a single property, but since MS does not support that, I guess there is a pretty good reason for this.

Thanks for your time explaining your reasoning in detail.

Cheers,
~Matt
Tags
Ajax
Asked by
surfer
Top achievements
Rank 1
Answers by
Vlad
Telerik team
surfer
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or