开发者

Parsing XHTML in a jQuery success callback doesn't work in IE

Here is a simple callback that is processed on a successful return from the Ajax

   Entropy . eBookHandler . fetchPageHandler = function ( data, status, request ) 
    { var container = jQuery ( this ); 
      var xhtml = jQuery ( data );
      var body = xhtml . find ( "body" );
      var div = body . children ( "div" );
      var clone = div . clone ( true );
      var content = container . children ( );
      if ( 0 < content . length )
       content . replaceWith ( clone );
      else
       container . prepend ( clone );

      Entropy . eBookHandler . bindContentHandlers ( );
    };

This is invoked after execution of the following jQuery .ajax method:

    jQuery . ajax 
        ( { context: container, type: 'GET',  url: page, 
            dataType: 'xml', async: true, cache: false, 
            timeout: 10000, 
            success: Entropy. eBookHandler.fetchPageHandler,
            error: Entropy.eBookHandler.ajaxErrorHandler 
        } ); 

This works perfectly in all browsers exc开发者_如何学Goept the IE series where the XHTML fragment requested is not loaded into the "host"DOM. The clone method is needed because the local DOM and that loaded as xhtml are of course different.

It's pretty clear that IE is behaving differently from all the other browsers, how do we fix this? (The return XHTML content verifies as XHTML 1.0 Exact at W3C)

I found a suggestion which is to treat IE separately by adding the following parenthesis:

if( jQuery.browser.msie)
{ var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.loadXML(data);
  xhtml = xmlDoc;
}

So will this work, or is there one code sequence that will work for all browsers?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜