Internet Explorer中的Jquery:查找图像问题(适用于FF和Chrome) [英] Jquery in Internet Explorer: find image problem(works in FF and Chrome)
问题描述
$。get(js / getflickreasy.php,function(data)
{
$(data).find(item)。 (function()
{
var title = $(this).find(title)。text();
var description = $(this).find(description) .text();
var thumbnail = $(description).find(img)。attr(src);
}
);
}
);
在Firefox和Chrome中,这很好用。但在Internet Explorer中,变量title和description将获得值。缩略图未定义。我知道它在IE中获取数据。 getflickreasy.php从flickr中检索rss。
我不认为它是IE缓存的问题,因为它在清除后是相同的。也许这是IE中的 $(this).find
的一些问题。
您可以查看以下代码我的网页
编辑:含$ .get它将检索数据,但Internet Explorer无法处理它。带$ .ajax的
目前根本无法检索数据。
编辑:我更改了php将获取图片的网址:
http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=xml
而不是:
http://api.flickr。 com / services / feeds / photos_public.gne?id = 42980910 @ N02& lang = en-us& format = rss_200
我添加了 header(content-type:text / xml);
到php文件。我认为它现在应该得到xml,对吗? Fiddler说:
HTTP / 1.1 200 OK
日期:2010年11月17日星期三20:45:43 GMT
服务器:Apache
X-Powered-By:PHP / 5.2.13
连接:关闭
内容类型:text / xml
内容长度:25878
但问题仍然存在(至少我认为是这样)。
嗯......您可能需要将数据类型设置为XML。而不是使用 $。get()
尝试 $。ajax()
:
$。ajax({
type:GET,
url:js / getflickreasy.php,
dataType: xml,
成功:函数(数据){
$(data).find(item)。each(function(){
var item = $(this),title ,描述,缩略图;
title = item.find(title)。text();
description = item.find(description)。text();
thumbnail = item.find(img)。attr(src);
});
}
});
问题很可能来自服务器的响应。
使用当前配置(使用 $ .ajax
方法),响应 正在IE收到了。我使用名为 fiddler 的工具验证了这一点。
<问题是,浏览器发送以下标题:
接受:application / xml,text / xml
但服务器的响应是:
Content-Type:text / html
直到你可以得到服务器要返回有效的XML标头,IE—以及 $ .ajax
方法—将继续失败。
这我会考虑IE正在做的事情的几次之一!其他浏览器不会失败的事实令人恼火。他们应该。这样你就不会觉得它是一个IE特定的问题。但是,我离题了。
$.get("js/getflickreasy.php", function(data)
{
$(data).find("item").each(function()
{
var title = $(this).find("title").text();
var description = $(this).find("description").text();
var thumbnail = $(description).find("img").attr("src");
}
);
}
);
In Firefox and Chrome this works fine. But in Internet Explorer the variables title and description will get the value "". Thumbnail is undefined. I know it gets data in IE. The getflickreasy.php retrieves rss from flickr.
I don't think it's a problem with IE cache because it's the same after clearing it. Maybe it's some problem with $(this).find
in IE.
You can view the code in action at my webpage
Edit: with $.get it will retrieve the data but Internet Explorer can't process it. with $.ajax it won't retrieve the data at all at the moment.
Edit : I changed the url that the php will get images to :
http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=xml
instead of :
http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=rss_200
and I added header("content-type: text/xml");
to the php file. I think that it should get xml now, right? Fiddler says:
HTTP/1.1 200 OK Date: Wed, 17 Nov 2010 20:45:43 GMT Server: Apache X-Powered-By: PHP/5.2.13 Connection: close Content-Type: text/xml Content-Length: 25878
But still the same problem (at least I think so).
Hmmm... You might need to set the datatype to XML. instead of using $.get()
try $.ajax()
:
$.ajax({
type: "GET",
url: "js/getflickreasy.php",
dataType: "xml",
success: function(data) {
$(data).find("item").each(function() {
var item = $(this), title, description, thumbnail;
title = item.find("title").text();
description = item.find("description").text();
thumbnail = item.find("img").attr("src");
});
}
});
The problem is most likely your response from the server.
With your current configuration (the one using $.ajax
method), the response is being recieved by IE. I verified this using a tool called fiddler.
The problem is, the browser is sending the following header:
Accept: application/xml, text/xml
But the response from the server is:
Content-Type: text/html
Until you can get the server to return a valid XML header, IE—and the $.ajax
method—will continue to fail.
This is what I would consider one of the few times that IE is doing something right! The fact that the other browsers do not fail is irritating. They should. That way you wouldn't be confused thinking it's an IE specific problem. But, I digress.
这篇关于Internet Explorer中的Jquery:查找图像问题(适用于FF和Chrome)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!