CoffeeScript 与 jquery ajax

发布于 2024-11-16 11:59:40 字数 304 浏览 2 评论 0原文

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

上面的代码有问题,无法编译成js

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日久见人心 2024-11-23 11:59:40

错误

Parse error on line 3: Unexpected 'IDENTIFIER'

编译器给出引用该行的

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

The 问题很简单,在 'html'error 之间没有逗号(或换行符)。这是固定代码:

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

我强烈建议使用带有内置“构建”命令的编辑器,尤其是可以处理选定文本的编辑器。它使语法错误更容易被发现。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文