Bug with combination of: jQuery 1.4, ajax/json, Firebug Lite and IE 8

I had just about concluded that jQuery's ajax calls wouldn't work with JSON data in IE 8, no matter what I tried. I found that I could use the jQuery 1.3.2 library and this fixed the problem, but 1.4 simply would not play ball with JSON ajax requests. Even when the JSON data returned was so simple that there was no question of it being in an invalid format. For example:

{"x":"a"}

This was regardless of whether I used a Java servlet to return the JSON data, or a simple, canned text file. Regardless of dataType or contentType. Regardless of GET vs POST. Regardless of whether I used $.ajax or $.getJSON. And it all works in Firefox 3.6.

Then it dawned on me to take out the reference to Firebug Lite and IT WORKED! Suddenly the problem vanished. It worked regardless of tinkering with the contentType in the response (in the servlet that is), or of the dataType I specify in the request.

The problem returns if I link to Firebug Lite again...even if my code never actually uses it.

Has anyone seen this kind of behavior, and does anyone have a fix or workaround? I'd hate to have to stop using Firebug Lite. Thanks for any insight. Again, the problem only occurs when you combine jQuery 1.4, Firebug Lite, JSON data, and IE 8.

Here is the ajax call to a servlet, if it matters:

$.ajax({
 cache: false,
 url:"http://localhost:8080/Performance_Reporting/TestServlet",
 type:"GET",
 contentType: "application/json",
 dataType: "json",
 timeout:30000,
 success: function(d, status, req)
 {
  $("#result").text(d.x);
 },
 error: function(req, status, err)
 {
  $("#result").text(req.responseText);
 }
})

我实际上也看到了纯HTML响应的相同问题。


I can't at the moment get the webservice to output the correct contentType, but I have been able to use $.ajax() in the latest version of jQuery by modifying my javascript code as follows...

$.ajax({
 cache: false,
 url:"http://localhost:8080/Performance_Reporting/TestServlet",
 type:"GET",
 contentType: "application/json",
 dataType: "text",
 timeout:30000,
 success: function(d, status, req)
 {
  $("#result").text($.parseJSON(d).x);
 },
 error: function(req, status, err)
 {
  $("#result").text(req.responseText);
 }
})

The difference is make the service expect TEXT not JSON, and then parse the JSON....

d = $.parseJSON(d);

Bodge, but fixed.

链接地址: http://www.djcxy.com/p/46094.html

上一篇: jQuery JSON响应总是触发一个ParseError

下一篇: 错误与组合:jQuery 1.4,ajax / json,Firebug Lite和IE 8