Side navigation
#48 closed bug (duplicate)
Opened July 07, 2006 07:31AM UTC
Closed November 17, 2006 10:19PM UTC
Last modified June 19, 2007 07:58AM UTC
Seach scope does not work as expected with content loaded via $.get
Reported by: | Enchos@gmx.net | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | ajax | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I tried to load content from another file via $.get, find an element inside that loaded content and put that inside the current document.
eg.
$.get("url", function(content){
var content = $("#stuff", content).html();
do something with content
});
In my case, the id to search for is already in the document. As a result, $("#stuff", content).html() returns the content of #stuff inside the current document, not from the content loaded via get. It looks like a bug with the search scope.
I put up an example page to demonstrate the problem:
http:bassistance.de/crap/scopebug/bug1.html
Click the link to bug2.html to see what should be loaded into the red box.
Attachments (0)
Change History (8)
Changed July 08, 2006 05:29PM UTC by comment:1
milestone: | → 1.0 |
---|---|
version: | → 1.0 |
Changed July 17, 2006 05:00AM UTC by comment:2
priority: | critical → minor |
---|---|
type: | bug → enhancement |
Changed August 09, 2006 05:30PM UTC by comment:3
type: | enhancement → bug |
---|
I've noticed this happening with element selectors as well:
$.get("url", function(content){
var content = $("title", content).text(); // do something with content
});
this code obtains the current document's title instead of the retrieved document's title.
Changed August 09, 2006 10:37PM UTC by comment:4
priority: | minor → major |
---|
Actually, these alerts don't even give you the same result; the first one displays the requested page's markup, while the second one displays the current page's markup.
$.get("url", function(xml){
alert(xml);
alert($(xml).html());
});
Changed August 17, 2006 05:09AM UTC by comment:5
milestone: | 1.0 |
---|---|
priority: | major → minor |
type: | bug → enhancement |
version: | 1.0 |
There are two different problems discussed in this report - the one originally posted about and the one supplied by frohoff. I'll talk about both.
1) Currently, this is not possible for the simple reason that XML documents, unless you've specified an explicit DTD, don't have an getElementById selector. Both #foo and .html() fail on non-HTML-DOM documents. This is a known issue, but one that probably won't be addressed until post-1.0.
It is for this reason that I'm going to re-classify this as an enhancement.
2) The second issue is with the content-type of the document. You must make sure that the document being returned from the server has the correct content type associated with it (explicitly, Content-type: text/xml). If, for some reason, you cannot change the header, and it is wrong, try this instead:
$.get("url", callback, "xml")
and it will try to parse it as an XML document instead.
Changed November 11, 2006 01:11PM UTC by comment:6
resolution: | → wontfix |
---|---|
status: | new → closed |
Changed November 13, 2006 02:17PM UTC by comment:7
resolution: | wontfix |
---|---|
status: | closed → reopened |
Changed November 17, 2006 10:19PM UTC by comment:8
resolution: | → duplicate |
---|---|
status: | reopened → closed |
type: | enhancement → bug |
This is especially tricky, considering that XML documents don't support the ID selector naturally - or innerHTML, for that matter. I'm going to file this as an enhancement and deal with it someday.