English 中文(简体)
Firebug关闭时返回JSON表单rails控制器时出现无效标签错误
原标题: invalid label error when returning JSON form rails controller when Firebug is closed

如果我打开了Firebug控制台,并在rails控制器中返回以下内容以响应ajax调用:

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

我收到一个无效的标签错误。但它工作得很好,因为萤火虫关闭了。

有什么想法吗???

问题回答

解决问题的办法是:

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

问题是浏览器将json视为jsonp,并向其添加回调。

这个命令解决了这个问题(至少对我来说)。

这似乎与使用JQuery1.5有关。您能确认JQuery 1.4.4不会发生这种情况吗?

我同意Tomer的观点,认为这是一个json与jsonp的问题,但他的代码并没有为我修复它。我通过添加以下jQuery代码(适用于1.4和1.6)来修复它:

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




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签