开发者

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

开发者 https://www.devze.com 2023-01-19 20:05 出处:网络
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

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 m开发者_JS百科atters:

$.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);
 }
})


I've actually seen the same problem with plain HTML responses, too.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消