2

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) -> 
1
  • I use js2coffee to help out with my js conversion from time to time. Commented Sep 7, 2011 at 16:26

1 Answer 1

4

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 ->.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.