如何查找表格的最后一行和自动触发的按钮

时间:2019-02-04 02:34:47

标签: jquery ajax laravel

我想知道是否可能。 我有插入客户详细信息的模块,如果客户已经存在,则操作推车模式将不会显示。否则如果客户成功注册,则基于其ID的操作车模式将自动显示(已触发)

场景:

  • 如果我单击“保存更改”,并且我的功能确定该用户尚未注册,则将显示购物车,否则它将显示该用户已存在。请在此处搜索表格上的信息。 < / li>

Registration form

我的客户表: Customer Table

我的Ajax函数:

   $('#save_customer_details').click(function () {

    var customer_address = $('input#destination-input').val();
    var customer_name = $('#customer_name').val();
    var customer_number = $('#customer_number').val();
    var customer_email = $('#customer_email').val();
    var customer_postal = $('#customer_postal').val();
    var customer_location = $('#customer_location').val();
    var customer_order = CKEDITOR.instances['customer_order'].getData();

    var formData = new FormData();
    formData.append('customer_name', customer_name);
    formData.append('customer_number', customer_number);
    formData.append('customer_email', customer_email);
    formData.append('customer_address', customer_address);
    formData.append('customer_location', customer_location);
    formData.append('customer_order', customer_order);
    formData.append('customer_postal', customer_postal);


    var int_length = ('' + customer_number).length;
    console.log(int_length);

    if (customer_name.length === 0 ||
      customer_number.length === 0 ||
      customer_email.length === 0 ||
      customer_address.length === 0 ||
      customer_postal.length === 0) {

      swal({
        title: "Please Fill The Empty Box.",
        icon: "warning",
        button: "Done",
      });

    }
    else if (customer_number.length != 11) {
      swal({
        title: "Customer Number Must Be 11 Digits.",
        icon: "warning",
        button: "Done",
      });
    }
    else {


      $.ajax({
        url: '/insert_customer_details',
        data: formData,
        type: 'POST',
        dataType: 'JSON',
        processData: false,
        contentType: false,
        success: function (response) {
          if (response == 'User Already Exist') {
            swal({
              title: "This User Already Exist Please do search!",
              icon: "warning",
              buttons: true,
              dangerMode: true,
            });
          }
          else {



            swal({
              title: "Sucessfully Registered",
              icon: "success",
              button: "Done",
            });



            $('#save_customer_details').modal('hide');
            $("button#show_cart").trigger("click");

          }
        },
        error: function (response) {
          console.log(response);
        }
      });

    }
  });

0 个答案:

没有答案