0
jQuery(function($) {
  // create a convenient toggleLoading function
  var toggleLoading = function() { $("#loading").toggle() };

  $("#new_post")
    .bind("ajax:loading",  toggleLoading)
    .bind("ajax:complete", toggleLoading)
    .bind("ajax:success", function(event, data, status, xhr) {
      $("#response").html(data);
    });
});

this is my js function (or Simone Carletti's) and I want to transform it to coffeescript, I am having trouble with the last two callbacks, though.

My coffeescript looks like this

jQuery ->
    $("#new_post")
    .bind("ajax:loading",  toggleLoading)
    .bind("ajax:complete", toggleLoading)
    .bind("ajax:success", (event, data, status, xhr) ->
        alert(data)
    .bind("ajax:failure", (event, data, status, xhr) ->
        alert(data)

but I am getting an Error: unclosed INDENT on line 21

thanks in advance

0

1 Answer 1

3

The problem here is simply that you have mismatched parentheses. The line

.bind("ajax:success", (event, data, status, xhr) ->
    alert(data)

never closes the .bind call. Change your code to

jQuery ->
    $("#new_post")
    .bind("ajax:loading",  toggleLoading)
    .bind("ajax:complete", toggleLoading)
    .bind("ajax:success", (event, data, status, xhr) ->
        alert(data))
    .bind("ajax:failure", (event, data, status, xhr) ->
        alert(data))

and it'll work just fine.

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

2 Comments

pretty show indetion is right, are you sure the last 4 lines of my coffeescript are correct? I wonder if i need any parenthesis or something...
Sorry, I assumed a tab/spaces issue, but on second glance it was a parens issue. I've changed my answer.

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.