Bug Tracker

Modify

Ticket #6061 (closed bug: invalid)

Opened 3 years ago

Last modified 15 months ago

jQuery won't find elements from ajax request data from within <head> tag

Reported by: mtajur Owned by:
Priority: Milestone: 1.4.2
Component: ajax Version: 1.4.1
Keywords: ajax, head, find Cc:
Blocking: Blocked by:

Description

If you do a ajax request using $.get(), and the result coming from the server is a full, valid xHTML 1.0 Transitional document, jQuery fails to find elements from the result that are placed inside the <head> tag, neither does jQuery find the <head> tag itself.

Example: $(function() {

$.get('some.html', function(data) { alert( $(data).find('head').size() ); });

});

If some.html is a full xHTML page, with <head> tag and everything, this should result in alerting "1", but instead, jQuery finds neither <head> tag from the result nor any of the tags inside <head>.

In case I made any errors in the example, I'm sorry, but I've tested this with many working examples and asked a question about in on Stack Overflow (see  http://stackoverflow.com/questions/2146594/how-to-replace-entire-css-of-a-page-after-an-ajax-request-with-jquery ) - no solutions so far. So it seems like a bug.

Change History

comment:1 Changed 3 years ago by john

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

Yep, that's correct - parsing straight HTML we only guarantee the contents of the body element. If you wish to access the XML of the page directly then I recommend that you explicitly make the file .xhtml or request it as XML, for example:

  $.ajax({ dataType: "xml", file: "some.html", success: function(data){ ... });

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.