单击按钮后显示回调

时间:2016-02-11 23:24:39

标签: javascript jquery

这是一个非常新的问题,但我无法想出这个问题因为它是一种不同的方法/写作方式然后我已经习惯了!

我正在使用应用程序“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

1 个答案:

答案 0 :(得分:0)

在你的通知模式对话框中,html标记添加类似

的内容
<div id="#puttexthere"></div>

然后你可以做

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

希望你需要什么。

相关问题