我想出$ .ajax而不是getJSON来进行调试。因为getJSON在IE(6,7或8)中没有报告错误,所以我试图弄清楚为什么jQuery插件没有在IE中将返回的图像绘制到屏幕上,而是在其他浏览器中。
所以我试了这个。有趣的是,它在IE中遇到错误事件,但不是Firefox,safari和其他的,我不知道为什么(这段代码工作得很好,并且在FireFox和其他版本中呈现我的数据很好)。我知道我返回的JSON是有效的:
$.ajax({
type: "GET",
url: "http://localhost:59396/sss/sssHandler.ashx?action=getproducts&ids=" + ids,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data.length);
carousel.size(allProductIDs.length);
if (numberOfImagesLeftToShow < numberOfImagesToDisplay) {
first += (numberOfImagesToDisplay - numberOfImagesLeftToShow);
}
var d = 0;
for (var i = first; i <= last; i++) {
if (d != undefined) {
// add data using index of the array returned by JSON (which starts at 0)
carousel.add(i, decode(data[d].ImageTag));
}
// set to last ProductID showing in Carousel
if (i == last) { lastProductID = parseFloat(data[d].ProductID); }
d++;
}
},
error: function() {
alert("An error has occurred. Please try again.");
}
});
我不知道自己还能做些什么来解决IE的原因是有与返回的JSON这么多的麻烦,或只是执行或者使用OR的getJSON此功能(数据) 。我在响应中也设置了标题而不是缓存。这不是问题。 问题出在什么原因,IE拒绝在响应中输入我的函数(数据)。
下面是返回的JSON这说明有效的(即使http://www.jsonlint.com/检查的话):
[
{
"ImageTag": "\u003cdiv class=\"CarouselItem
\"\u003e<p><img src="http://www.xxx.com/image/
2568.jpg" alt=""></p>\u003cp\u003e\u003ca href=
\"Bear-10.prod\"\u003eTeddy Bear\u003c/a\u003e\u003c/p\u003e\u003cp
\u003e$20.95\u003c/p\u003e\u003cdiv\u003e",
"ProductID": "540"
},
{
"ImageTag": "\u003cdiv class=\"CarouselItem
\"\u003e<p><img src="http://www.xxx.com/image/
50.jpg" alt=""></p>\u003cp\u003e\u003ca href=
\"Pendant362.prod\"\u003eBirthday\u003csup\u003e©\u003c/sup
\u003Necklace\u003c/a\u003e\u003c/p\u003e\u003cp\u003e$36.95\u003c/p
\u003e\u003cdiv\u003e",
"ProductID": "83"
}
]
在我.ashx的
我只是有以下主要代码产品的响应
context.Response.ContentType = "application/json";
context.Response.Charset = Encoding.UTF8.ToString();
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetValidUntilExpires(false);
context.Response.Expires = -1;
context.Response.ExpiresAbsolute = DateTime.MinValue;
context.Response.AddHeader("Cache-Control", "no-cache");
context.Response.AddHeader("Cache-Control", "post-check=0, pre-check=0");
context.Response.AddHeader("Pragma", "no-cache");
...
string jsonString = imageList.ToJSON(); <-- uses the .NET 3.5 JavaScriptSerializer
context.Response.Write(jsonString);
也,如果您将response.ContentType指定为“application/json”或“text/plain”,似乎并不重要,因为至少我在FireFox中返回并分析了有效数据。
跑了它。相同的结果。在FireFox中运行良好,但不是IE8。它遇到错误:并且我得到Line:163 错误:系统错误:-1072896658。第163行是我的错误:function(){ alert(“发生错误,请重试。”); } – PositiveGuy 2009-07-06 18:57:37
实际上我确实想返回那里的HTML,它只会是img标签...没什么重要的。 – PositiveGuy 2009-07-06 19:06:24