Reputation: 4222
I have a rails 3.1 app and I am making an ajax call with jquery when a user clicks a checkbox.
Everything seems to work as expected but I am getting the following error in the console
Uncaught TypeError: object is not a function
(anonymous function)application.js:9329
jQuery.event.handleapplication.js:2966
jQuery.event.add.elemData.handle.eventHandle
here is the coffeescript that I have for the page that I am loading
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) ->
Upvotes: 2
Views: 1152
Reputation: 77416
It's because of the line
current_id = $(this).attr("id") ->
which is equivalent to
current_id = $(this).attr("id")(->)
$(this).attr("id")
returns a string, so that's why you get an object is not a function
error. Just ditch the ->
.
Upvotes: 4