JQuery.load () XHTML Problem

I'm having some weird issues loading content from another XHTML page through jQuery. When the second page I'm trying to load is served as XHTML, I get the following error. I don't know if this helps, but both documents check when I get an error.

Unprepared error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7

Currently, the title on the second page I'm loading is:

<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="language" content="en" /> <title>some title</title> <!-- CSS & Javascript included here --> </head> 

The content type is specified as:

application / XHTML + XML; encoding = iso-8859-1

Interestingly, when I remove all XHTML content from the header and stop setting the content type, an error does not occur and everything works fine .

Now the download process is as follows. It works great when everything is plain HTML.

 $('#overpage').find(".wrap").load(this.getTrigger().attr("href")+" #op").show(); 

I am curious why this process does not work when the second page I load is XHTML. I don’t want to display the page as plain HTML, and I’m looking for tips on what I'm doing wrong. Both pages are checked and I really scratch my head. Many thanks!

+4
source share
3 answers

I think this is due to the fact that document.write does not work with XHTML strict:

http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

+3
source

I ran into the same problem a little back, I think this is because jquery accepts (X) the HTML that it receives, inserts it into a dummy div and only then starts the selector (#op in your case) to extract correct part and insert it in the final place. Here's the corresponding jquery code (taken from 1.5.1, but 1.6 looks the same):

 jQuery("<div>") // inject the contents of the document in, removing the scripts // to avoid any 'Permission Denied' errors in IE .append(responseText.replace(rscript, "")) // Locate the specified elements .find(selector) 

In Firebug, I see that it has errors in the .append line, because it doesn’t have the grok header <?xml or <DOCTYPE inside the div ... So I think this is just something jquery doesn't, sure how this could be corrected in a reasonable way.

+2
source

XHTML does not support document.write or innerHTML. Because jQuery inserts new code using one of these methods, all XHTML-compatible browsers will fail.

XHTML with the application / xhtml + xml does not support the original source modification using any of these jQuery methods: append (), html (), insert ... (), etc.

Instead, request JSON data and paste the resulting AJAX values ​​into predefined tags using .text () /. Val () or dynamically create these nodes using document.createElement ('someTag').

+1
source

Source: https://habr.com/ru/post/1299222/


All Articles