按钮点击后显示回调

问题描述:

这是一个很新的问题,但我无法弄清楚这一点,因为它是一种不同的方法/写作方式,我习惯了!按钮点击后显示回调

我使用的应用程序“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); 

    }); 

} 

我如何展示msgnotificationCallback每次我点击模态内的提交按钮?

在您的通知模态对话框的HTML标记放像

<div id="#puttexthere"></div> 

那么你可以做

$('#puttexthere').text(msg); 

你需要什么希望。