我在 SO 和其他地方看到过很多其他人遇到这个问题,但给定的解决方案似乎都不适合我。
我有一个对 ASHX 处理程序的 jQuery AJAX 调用。该代码适用于 Firefox 和 Chrome,但不适用于 IE(版本 8、9 或 10)。
它看起来像这样(简化):
var val = $(this).val();
$.ajax({
url: '/Source/Handlers/Search.ashx?q=' + val,
type: "GET",
cache: false,
dataType: 'json',
error: function(w,t,f) {
alert(w + "\n" + t + "\n" + f);
},
success: function (data) {
...
}
});
当我在 IE 中运行代码时,错误处理程序会启动并说
[object Object]
error
error
有用吧?
ASHX 处理程序是这样的(再次简化):
public class Search : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.ContentType = "application/json";
context.Response.Buffer = false;
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Suggestions> jsonResponse = new List<Suggestions>();
// do some stuff
context.Response.Write(serializer.Serialize(jsonResponse));
}
}
我尝试将“GET”换成“POST”,尝试启用和禁用“cache”属性,尝试不同的数据类型设置,例如“json”、“xml”和“text”。
使用 HTTP Fiddler 我可以看到 json 响应确实回来了,但 IE 似乎无法处理它。
有任何想法吗?
编辑
这是来自 HTTP Fiddler 的 TextView 中的 JSON 响应:
543
[{"title":"GAMES","results":[{"title":"abcdefg™","link":"http://www.abcdefg.com/en_gb/abcdefg/","image":"/uploadedImages/abcdefg/games/1-Game_Folder_Master(1)/Config/abcdefg(1).jpg","total":""},{"title":"abcdefg","link":"http://www.abcdefg.com/en_gb/abcdefg","image":"/uploadedImages/abcdefg/games/1-Game_Folder_Master(1)/Config/abcdefg.jpg","total":""},{"title":"abcdefgg","link":"/Retailers/?game=1432&platform=0","image":"/uploadedImages/abcdefg/games/1-Game_Folder_Master(1)/Config/abcdefg.jpg?n=9736","total":""},{"title":"abcdefg","link":"http://www.abcdefg.com","image":"/uploadedImages/abcdefg/games/1-Game_Folder_Master(1)/Config/abcdefg.jpg","total":""},{"title":"abcdefg","link":"/Retailers/?game=1763&platform=0","image":"/uploadedImages/abcdefg/games/1-Game_Folder_Master(1)/Config/abcdefg_promo.jpg","total":""}],"total":"24","link":"/Search/?q=total"},{"title":"MEDIA","results":[{"title":"Videos","link":"/Search/?q=total","image":"","total":"1"},{"title":"Screenshots","link":"/Search/?q=total","image":"","total":"35"}],"total":null,"link":null}]
0
编辑 2
嗯,我更新了 $.ajax 调用以提醒 w.status 并返回“404”。困惑 - 当 Fiddler 将响应显示为 200 时,它如何返回 404 状态?