Coffeescript/JQuery/Rails:$.ajax - 解析错误,意外 '{'
我已经有一段时间无法克服简单的解析器错误了。我在网上找到了几个代码示例,这些代码示例似乎很相似 - 我将非常感谢您的提示!
$ ->
$(".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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您使用的 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
使用在线编译器 http://coffeescript.org/ 时,您的摘录可以正常编译
Your excerpt compiles fine while using the online-compiler at http://coffeescript.org/