2011-09-07 123 views
2

我有一个rails 3.1应用程序,当用户单击复选框时,我正在用jquery调用ajax。coffeescript jquery rails未捕获类型错误

似乎一切都按预期工作,但我收到以下错误控制台

Uncaught TypeError: object is not a function 
(anonymous function)application.js:9329 
jQuery.event.handleapplication.js:2966 
jQuery.event.add.elemData.handle.eventHandle 

这里是我的页面的CoffeeScript中,我加载

jQuery -> 
$(".checkbox").click -> 
    current_id = $(this).attr("id") -> 

    obj = 
     url: "/challenge/public?id=" + current_id 
     success: (data) -> alert data.result 
     error:() -> alert "error" 

    $.ajax(obj) -> 
+0

我使用[js2coffee](http://js2coffee.org/)来帮助我时常转换我的js转换。 – ace

回答

4

这是因为的线

current_id = $(this).attr("id") -> 

这相当于

current_id = $(this).attr("id")(->) 

$(this).attr("id")返回一个字符串,所以这就是为什么你得到一个object is not a function错误。只沟->