Coffeescript/JQuery/Rails:$.ajax - 解析错误,意外 '{'

发布于 2024-12-28 04:26:36 字数 407 浏览 4 评论 0原文

我已经有一段时间无法克服简单的解析器错误了。我在网上找到了几个代码示例,这些代码示例似乎很相似 - 我将非常感谢您的提示!

$ ->
  $(".category_modal").click (e) ->
    alert "Hi"
    e.preventDefault()
    $.ajax 
      url: 'entries/detail'
      type: "GET"  <-- Error: Parse error on line 28: Unexpected '{'
      dataType: 'json'
      success: (data) ->
        alert "Hi again"
        $(".category_modal").html(data)

I don't manage to get past a simple parser error for quite some time now. I found several code sample on the web and those seem to be similar - I would deeply appreciate a hint!

$ ->
  $(".category_modal").click (e) ->
    alert "Hi"
    e.preventDefault()
    $.ajax 
      url: 'entries/detail'
      type: "GET"  <-- Error: Parse error on line 28: Unexpected '{'
      dataType: 'json'
      success: (data) ->
        alert "Hi again"
        $(".category_modal").html(data)

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

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

发布评论

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

评论(2

七秒鱼° 2025-01-04 04:26:36

根据您使用的 IDE,我发现编译 Coffescript 文件时经常会由于格式错误的空格而出错。

解决方案:将“type:”之前的空格以及上一行末尾的空格,即:“tries/detail”之后的空格全部

删除,重新组成并再次尝试编译。尤其是当我从其他来源复制粘贴时,会发生这种情况

Depending on the IDE you use, I have found out that oftentimes I get errors compiling Coffescript files due to malformed spaces.

Solution: Select all the spaces before 'type:' AND the ones on the end of the previous line, ie after: 'tries/detail'

Delete them, and form them again and try again to compile. This happens especially when I copy-paste from other sources

很酷不放纵 2025-01-04 04:26:36

使用在线编译器 http://coffeescript.org/ 时,您的摘录可以正常编译

Your excerpt compiles fine while using the online-compiler at http://coffeescript.org/

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