我试图调用一个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/