1
這是一個很新的問題,但我無法弄清楚這一點,因爲它是一種不同的方法/寫作方式,我習慣了!按鈕點擊後顯示回調
我使用的應用程序「Back in Stock」的網店是不是 shopify但類似的東西。此應用程序顯示產品缺貨時的模式,用於註冊您的電子郵件以接收更新。
此外,我創建了自己的模式,因爲翻譯問題和更多國家相關的東西。
我在創建或運行某個函數以顯示成功或錯誤消息時遇到麻煩,當我單擊按鈕時。
文檔說,這是抓住所有消息的方式:
var notificationCallback = function(data) {
var msg = '';
if (data.status == 'OK') {
msg = data.message; // just show the success message
} else { // it was an error
for (var k in data.errors) { // collect all the error messages into a string
msg += data.errors[k].join();
}
}
alert(msg);
}
我創建了一個功能,顯示彈出式窗口,處理提交:
<button class="notify_button pp pull-right" data-product-id="{{ product.id }}" data-variant-id="{{ product.vid }}" onclick="notify_me_function(this,event);">{{ 'Email when available' | t }}</button>
function notify_me_function(el ,event){
var variantId = $(el).data('variant-id');
var productId = $(el).data('product-id');
var itemName = $(el).closest('.item').find('.item-name').text();
$('#notify__').modal('show');
$('#notify__ #notify_button').on('click', function(e) {
e.preventDefault();
var email = $('#notify__ .form-horizontal input').val();
var $container = $('.completed_message');
// this piece of code below is also from the docs /////////
BIS.create(email, variantId, productId).then(notificationCallback);
//something like this?? ///
$container.txt(msg);
});
}
我如何展示msg
從notificationCallback
每次我點擊模態內的提交按鈕?