JQuery in internet explorer cant parse a string html
I am trying to parse an HTML string in Internet Explorer using jQuery, based on: Parsing HTML String with Ajax/开发者_开发知识库jQuery. here is the code:
alert(result);
alert($(result));
The first alert prompts the HTML, but second alert just gives me Object. On firebug lite console it gives me a blank object: [] !!
console.log(result)
console.log($(result))
result is a big XHTML code, that is received through an AJAX call. The same code works on Firefox..
Anyone has any idea why this could be happening? Your help is much appreciated..!
Without seeing the HTML code, it's hard to say, but I would have to guess that you're hitting the "Unknown runtime error" that occurs when you're invalidly trying to put an element where it's not allowed.
You see, jQuery builds the DOM from (X)HTML by creating a detached element and applying the (X)HTML to that element's innerHTML
property. FWIW, neither browsers care if you're passing XHTML or HTML, unless you're serving an XHTML mime type that would be giving you bigger problems. If you consider the following plain JS code:
var p = document.createElement("p");
p.innerHTML = "<li>Test</li>";
Internet Explorer with throw a very unhelpful "Unknown runtime error", whereas Firefox will do its best to salvage the invalid HTML.
I would recommend putting your XHTML through the W3C Validator and checking it for validation errors.
精彩评论