如何确定Java脚本功能是否仍在运行?

时间:2019-04-27 12:27:09

标签: javascript jquery

我对javascript函数感到担忧,这个问题是否有任何指标可以确定javascript函数是否仍在运行或仍在运行?因为我在插入数百个要插入数据库的项目时遇到问题。我想确定如果javascript函数仍在继续,插入将一直保持到条件满足为止,否则,如果javascript函数未运行或未完成,它将自动重定向到另一页。

在我对jquery的onclick中,我插入了javascript函数。

    $('#add_to_cart').on('click', function() {

  orders = [];
  menu = undefined;

  $('.tbody_noun_chaining_order').children('tr').each(function() {
    $row = $(this);
    if ($row.hasClass('condimentParent')) {
      if (menu) {
        orders.push(menu);
      }
      menu = {
        'total': $row.find('.total').text(),
        'name': $row.find('.parent_item').text(),
        'customer_id': customer_id,
        'condiments': {
          'Item': [],
          'Qty': [],
          'Total': []
        }
      };

    } else if ($row.hasClass('editCondiments')) {

      menu.condiments.Item.push($row.find('.child_item').text());
      menu.condiments.Qty.push($row.find('.condiments_order_quantity').text());
      menu.condiments.Total.push($row.find('.total').text());
    }
  });

  if (menu) {
    orders.push(menu);
  }





  storeOrder(orders)




});

我的Javascript函数

    function storeOrder(data) {

  var customer_id = $('#hidden_customer_id').val();
  var place_customer = $('#place_customer').text();

  $id = "";
  $total_amount  = $('.total_amount').text();
  $append_customer_noun_order_price = $('.append_customer_noun_order_price').text();
  $tax_rate = $('.rate_computation').text();
  $delivery_rate = $('.del_rate').text();

  var sessionTransactionNumber_insert = localStorage.getItem('sessionTransactionNumber');

    $.ajax({
      url:'/insert_customer_order_properties',
      type:'POST',
      data:{
        'hidden_customer_id': customer_id,
        'hidden_customer_address': place_customer,
        'sessionTransactionNumber': sessionTransactionNumber_insert
      },
      success:function(data) {

        $id = data[0].id;

        $.ajax({
          url:'/insert_customer_payment_details',
          type:'POST',  
          data:{
            'hidden_customer_id': customer_id,
            'total_amount': $total_amount,
            'customer_sub_total': $append_customer_noun_order_price,
            'tax_rate': $tax_rate,
            'id_last_inserted': $id
          },
          success:function(data) {

             localStorage.removeItem('sessionTransactionNumber');

          }
        })
      }
    })

  for (var num in orders) {

    $.ajax('/insert_wish_list_menu_order', {
      type: 'POST',
      context: orders[num].condiments,
      data: {
        'append_customer_noun_order_price': orders[num].total,
        'append_customer_noun_order': orders[num].name,
        'customer_id': customer_id
      },
      success: function(orderNumber) {

        $order_number = orderNumber[0].id;

        $.ajax({
          url:'/insert_customer_order_details_properties',
          type:'POST',
          data:{
            'order_number': $order_number,
            'data_attribute_wish_order_id': $id,
          },
          success:function(data) {

              console.log(data);

          }
        })

        if (orderNumber !== undefined) {

          $.ajax('/insert_wish_list_menu_belong_condiments', {
            context: orderNumber,
            type: 'POST',
            data: {
              'ParentId': orderNumber,
              'Item': this.Item,
              'Qty': this.Qty,
              'Total': this.Total
            },
            success: function(result) {

              console.log(result);

            },

          })

        }
      }
    })
  }
}

0 个答案:

没有答案