12
$.ajax '/',
    type: 'GET'
    dataType: 'html' error: (jqXHR, textStatus, errorThrown) ->
        $('body').append "AJAX Error: #{textStatus}"
    success: (data, textStatus, jqXHR) ->
        $('body').append "Successful AJAX call: #{data}"

there is something wrong with the above code,I can't compile it into js

3
  • 1
    -_-|||,i found the reason , it mixed with "tab" and "space" ,so it can't work Commented Jun 19, 2011 at 6:01
  • no,i use the coffeescript.js in the webpage ,not the command line,so nothing appeared , and how to debug the coffeescript ? Commented Jun 19, 2011 at 6:06
  • 1
    When using coffee-script.js, you should see compile-time errors on your browser's console. If your browser doesn't have a console, grab the Firebug Lite bookmarklet. Commented Jun 19, 2011 at 19:28

1 Answer 1

27

The compiler gives the error

Parse error on line 3: Unexpected 'IDENTIFIER'

referring to the line

dataType: 'html' error: (jqXHR, textStatus, errorThrown) ->

The problem is simply that there's no comma (or line break) between 'html' and error. Here's the fixed code:

$.ajax '/',
    type: 'GET'
    dataType: 'html'
    error: (jqXHR, textStatus, errorThrown) ->
        $('body').append "AJAX Error: #{textStatus}"
    success: (data, textStatus, jqXHR) ->
        $('body').append "Successful AJAX call: #{data}"

I highly recommend using an editor with a built-in "Build" command, especially one that can work on selected text. It makes syntax errors a lot easier to pin down.

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

3 Comments

NetBeans is one such editor that so far I like for a free IDE. Look under tools->plugins to add the CoffeeScript plugin then right click your .coffee file and select CoffeeScript->autocompile. No need to install commandline tools.
@trevor do you recommend a particular build system for the editor? Ideally Sublime Text? Currently I am using a build system as part of a framework.
@Scoop If you're using the official CoffeeScript tmbundle with ST2, there should already be a Build command that works for your CoffeeScript.

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.