2011-09-07 149 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錯誤。只溝->