开发者

coffeescript with jquery ajax

$.ajax '/',
    type: 'GET'
    dataType: 'html' error: (jqXHR, textStatus, errorThrown) ->
        $('body').append "AJAX Error: #{textStatus}"
    s开发者_运维百科uccess: (data, textStatus, jqXHR) ->
        $('body').append "Successful AJAX call: #{data}"

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜