简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM