I've Googled around, but I can't quite find a good solution to this problem. IE's developer tools haven't helped much on this front either.
This code for an xml document returned via ajax works in Safari, Chrome and Firefox:
$(data).find('Ticket').length;
The code returns, for example, the number 3.
The same code returns 0 in Internet Explorer 8. Why?
I have no doubt there's a simple explanation that involves either a) an IE quirk or b) a fault in my code that the other browsers forgive.
find doesnt work in IE with custom tags (xml) unless you construct an activeX object
assuming the variable 'xml' is what is the xml returned from your request
var data;
if ($.browser.msie)
{
data = new ActiveXObject("Microsoft.XMLDOM");
data.async = false;
data.loadXML(xml);
}
else
{
data = xml;
}
//your code here
Edit: Next answer.
Try
$('Ticket', data).length;
IE grabs xml differently than other browsers, firefox and chrome, alert($data) see if it is empty
Try out $(data).find('ticket').size()
. This returns the same result as of $(data).find('ticket').length
Firstly, find()
does in fact work in IE8, although perhaps it didn't back in February 2011.
In any case, I had exactly this problem today, and for me it was caused by the original ajax request: I had dataType: 'html'
instead of dataType: 'xml'
.
It's a silly mistake, but worth checking for.
精彩评论