在ajax提交之前显示提示

时间:2018-06-10 10:50:51

标签: jquery ajax prompt

我正在尝试让用户在ajax将数据提交到db之前输入更新数量的原因。

这是jquery代码,它向更新db的php脚本发送qty更改。由于某种原因,我无法停止ajax并显示用户显示的提示,因此他可以写出他更新数量的原因。有人能告诉我为什么没有显示提示?

<form name="form1" id="form1" method="POST" action="update_qty.php">
<input type="text" name="update_qty" class="update_qty" id="qty" value="<?php echo $sales_value['qty'] ?>"><?php echo ' Kom'; ?>
<input type="hidden" name="article_id" id="article_id" value="<?php echo $sales_value['article_id']; ?>">
<input type="hidden" name="sales_plan_id" id="sales_plan_id" value="<?php echo $sales_plan_id; ?>">
<input type="hidden" name="product_mix_id" id="product_mix_id" value="<?php echo $product_mix_id; ?>">
</form>

    //Update qty on article
$(document).ready(function() {

    $('.update_qty').on('change', function() {

        var message = prompt("Upišite razlog za izmjenu količine:");
        alert(message);
        //e.preventDefault();
        var article_id = $("#article_id").val();
        var sales_plan_id = $("#sales_plan_id").val();
        var update_qty = $(this).val();
        var product_mix_id = $("#product_mix_id").val();


        if (message != "" || message != NULL) {
            $.ajax({
                type:'POST',
                url:'update_qty.php',
                data:{ article_id: article_id, sales_plan_id: sales_plan_id, update_qty: update_qty, product_mix_id: product_mix_id, message: message },
                success:function(data) {
                    alert(data);
                }
            });
        } else {
            e.PreventDefault();
            return false;
        }

    });

});

1 个答案:

答案 0 :(得分:0)

使用beforesend尝试这样做。

更新

    $(document).ready(function() {
var message;

      $('#update_qty').on('blur', function() {

    //e.preventDefault();
    var article_id = $("#article_id").val();
    var sales_plan_id = $("#sales_plan_id").val();
    var update_qty = $("#update_qty").val();
    var product_mix_id = $("#product_mix_id").val();



      $.ajax({
        type:'POST',
        beforesend:con(),
        url:'update_qty.php',
        data:{ article_id: article_id, sales_plan_id: sales_plan_id, update_qty: update_qty, product_mix_id: product_mix_id },
        success:function(data) {
          alert(data);
        }
      });


  });

});

function con(xhr){
    message=prompt('enter reason');
    if(message==''){
     xhr.abort();

     }
    }
相关问题