开发者

'invalid label' error when returning JSON form rails controller when Firebug is closed

开发者 https://www.devze.com 2023-01-20 20:23 出处:网络
If I have Fi开发者_如何学运维rebug console open, and return the following in a rails controller in response to an ajax call:

If I have Fi开发者_如何学运维rebug console open, and return the following in a rails controller in response to an ajax call:

format.json { render :json => Appointment.find_by_id(1) } 

I get an 'invalid label' error. But it works fine it Firebug is closed.

Any ideas???


What solved it for me was:

jQuery.ajaxSetup({
          jsonp: null,
          jsonpCallback: null
        });

The problem is that the browser treats the json as jsonp and adds a callback to it.

This command solves it (at least for me).


This seems to be related to using JQuery 1.5. Could you confirm that this doesn't happen with JQuery 1.4.4?


I concur with Tomer that this is a json-vs-jsonp problem, but his code didn't fix it for me. I fixed it by adding this jQuery code (works in 1.4 and 1.6):

$(function() {
  $.ajaxSetup({
    dataType: 'json'
  });
});
0

精彩评论

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