我使用coffeescript获取引用错误

时间:2014-08-02 20:29:39

标签: 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())

1 个答案:

答案 0 :(得分:1)

你需要

balanced.card.create(payload, handleResponse)

而不是

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