Bug Tracker

Modify

Ticket #8941 (closed bug: invalid)

Opened 2 years ago

Last modified 4 weeks ago

script error - invalid or illegal string when calling .load() on doc with DOCTYPE

Reported by: jaraco@… Owned by:
Priority: low Milestone: 1.next
Component: ajax Version: 1.5.2
Keywords: Cc:
Blocking: Blocked by:

Description

I create a simple harness.xhtml to load jQuery:

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js" type="text/javascript"></script>
  <script type="text/javascript">
	$(document).ready(function() {
		$("#main_cont").load("widget.html");
	});
  </script>
</head>
<body>

  <div id="main_cont">
  </div>

</body>
</html>

And then I create the file widget.html:

<!DOCTYPE html>
<html><body><div>
  Got it!
</div></body></html>

When I open harness.xhtml in Firefox 4 (either from a hosted location or using a  file:// url), I get the following script error:

An invalid or illegal string was specified"  code: "12
https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js
Line 5620

If I remove the <!DOCTYPE html> line from the widget.html, it loads as I would expect, there is no script error, and the browser displays "Got it!".

It appears that single <!DOCTYPE> declaration is sufficient to prevent firefox from loading the content dynamically.

Nothing in the docs suggests why this would be the case. In fact, the examples from the docs appear to have <!DOCTYPE html> declarations.

Change History

comment:1 Changed 2 years ago by anonymous

I looked into creating a jsFiddle for this bug, but I don't see how I can create widget.html such that a jsFiddle page could load that URL. I'll try loading remotely.

comment:2 Changed 2 years ago by jaraco

I created  this jsfiddle, but it doesn't reproduce the problem.

Here's  the harness hosted on Dropbox where you can see the behavior.

comment:3 Changed 2 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

The XHTML doctype pledges that you are going to create valid documents. The documentation for .load() says:

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

The markup being inserted into the <div> isn't valid there in XHTML. You could try Ben Alman's HTMLDoc plugin:  http://benalman.com/projects/jquery-misc-plugins/#htmldoc .

comment:4 Changed 2 years ago by timmywil

#8972 is a duplicate of this ticket.

comment:5 Changed 2 years ago by rwaldron

  • Priority changed from undecided to low
  • Component changed from unfiled to ajax

comment:6 Changed 4 weeks ago by marco.falsitta@…

Issue for me as well. Index page without <!DOCTYPE html> performs a load() as expected.

$(someSelector).load("locationofhtmlresource.html .targetClass", function(response){
   
   $(this).html(); //---> EMPTY, the html fragment is the response variable but no  loaded html is appended to the original selector

})

after removing <!DOCTYPE html> or simply adding some garbage like <!DOCTYPE blabla> or <!DOCTYPE>

$(someSelector).load("locationofhtmlresource.html .targetClass", function(response){
   
   $(this).html(); //---> CORRECT, the html fragment is s appended to the original selector

})

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.