Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#8941 closed bug (invalid)

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

Reported by: [email protected] Owned by:
Priority: low Milestone: 1.next
Component: ajax Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

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 (6)

comment:1 Changed 11 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 11 years ago by Jason R. Coombs

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 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

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 11 years ago by timmywil

#8972 is a duplicate of this ticket.

comment:5 Changed 11 years ago by Rick Waldron

Component: unfiledajax
Priority: undecidedlow

comment:6 Changed 8 years ago by [email protected]

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

})
Note: See TracTickets for help on using tickets.