-1
目前我正在開發一個Ruby on Rails應用程序,並且試圖讓下面的JS與該應用程序一起工作。我遇到的第一個問題是turbolinks 5.0阻止了頁面在初始加載時加載JS,爲了加載下面的JS,我必須刷新頁面。我做了一些Google搜索,並遇到this stackoverflow answer,但我似乎無法讓JS正常運行而不會拋出錯誤。任何和所有的幫助將不勝感激。Javascript類型錯誤:變量未定義
orders.js
console.log('inside orders.js');
$(document).on('turbolinks:load', function() {
// Your JS here
var payment;
jQuery(function() {
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
return payment.setupForm();
});
payment = {
setupForm: function() {
return $('#new_order').submit(function() {
$('input[type=submit]').attr('disabled', true);
Stripe.card.createToken($('#new_order'), payment.handleStripeResponse);
return false;
});
},
handleStripeResponse: function(status, response) {
if (status === 200) {
// return alert(response.id);
$('#new_order').append($('<input type="hidden" name="stripeToken" />').val(response.id));
return $('#new_order')[0].submit();
} else {
// return alert(response.error.message);
return $('#stripe_error').text(response.error.message).show();
}
}
};
});
' 「沒有出現任何的錯誤」「 - 有什麼錯誤?哪一行會引發錯誤?發生這種情況時的運行時間值是什麼? – David
Jquery(function(){return「sth」});是無稽之談 –
沒有很多細節我會說這是因爲你正在用'$'準備好jQuery,然後再次檢查jQuery是否已經準備好了'jQuery',基本上調用兩次不同的值準備好'$'vs' jQuery' –