javascript - 我使用 CoffeeScript 时遇到引用错误

标签 javascript jquery ruby-on-rails coffeescript

我试图调用一个handleResponse函数,它声明它是未定义的。我似乎无法弄清楚,因为它们位于同一个 $document.ready 函数中。

jQuery ->
handleResponse(response) ->
    if (response.status_code == 201)
        fundingInstrument = response.cards != null ? response.cards[0] 
        jQuery.post("models/Tablecharge", 
            uri : fundingInstrument.href,
            (r) ->
                if (r.status == 201) 
                    redirect_to @table
                else
                    render 'new'
        )
$('#cc-submit').click (e) ->
    e.preventDefault()

    payload = 
    name: $('#cc-name').val()
    number: $('#cc-number').val(),
    expiration_month: $('#cc-ex-month').val(),
    expiration_year: $('#cc-ex-year').val(),
    cvv: $('#ex-cvv').val(),

balanced.card.create(payload, handleResponse())

最佳答案

你需要

balanced.card.create(payload, handleResponse)

而不是

balanced.card.create(payload, handleResponse())

关于javascript - 我使用 CoffeeScript 时遇到引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25099140/

相关文章:

javascript - 选择 2 JS - 忽略 HTML 标记

javascript - 如何在 Greasemonkey 脚本中包含远程 javascript 文件?

javascript - 这个语法在javascript中意味着什么

ruby-on-rails - Rails 3.2.8 中的强参数

javascript - 重新运行 PHP rss feed

javascript - 为什么 document.getElementById 在我的脚本中不起作用?

javascript - 处理背景色覆盖时边框底部不起作用

javascript - D3拖动事件触发的频率是多少?

ruby-on-rails - Rails 确定来自 accepts_nested_attributes_for 对象的对象是否已更改?

ruby-on-rails - ruby : do nothing (dummy) function