Вызов ajax в PHP Jquery не увеличивает значение переменной в случае успеха ajax - PullRequest
0 голосов
/ 15 июня 2019

Я хотел бы увеличить значение переменной на единицу при успешном вызове ajax. Я использовал следующий скрипт, но не увеличивал значение переменной, он всегда возвращал определенное значение.

jQuery(".custom_product_box_add").click(function(e){
        var product_id =jQuery(this).attr('data-product_id');
        var product_qty =jQuery(this).attr('data-quantity');
        var product_box_id =jQuery(this).attr('product_box_id');
        var variation_id =jQuery(this).attr('variation_id');
        var qty_value = jQuery(this).attr("currentQty");
        var inputQtyNumber =jQuery(this).parent().prev().val(qty_value)

       var parent = jQuery(this).parent().parent().parent().parent().attr('id');

          var data = {
            action: 'woocommerce_custom_ajax_add_to_cart',
            product_id: product_id,
            product_sku: '',
            quantity: product_qty,
            product_box_id:product_box_id,
            variation_id: variation_id
        };

    var limit=0;

        jQuery.ajax({
            method: 'post',
            dataType: "json",
            url:veh_app_script.ajaxurl,
            data: data,

            beforeSend: function (response) {
               jQuery("#loading").show();
            },
            complete: function (response) {
              jQuery("#loading").hide();
            },
            success: function (response) {
                console.log(response)
                if( response.error != 'undefined' && response.error ){
                      return true;
                 } else {                  
                     setTimeout(function() {

                        var jsonRsponse =response.data;
                        console.log(JSON.parse(response.data_product_string));
                      //  return false;
                        var html = '';
                          html +='<div class="row">';

                          jQuery.each(jsonRsponse,function(key,value){
                              html +='<div class="col-sm-3 col-xs-12 mb_20">';
                              html +='<image width="300" height="300" src='+ value.image[0] + '>';
                              html +='<p class="qty_value">'+ value.qty + '</p>';
                              html +='</div>';

                          });
                         html +='</div>';
                         jQuery('.cart_product').html(html);


                    }, 2000);



                  }

                  limit = parseInt(limit) + 1; // First Way
limit++ // Second way

                  console.log('limit'+ limit  );

            }

        });

        return false;
    });

Я пытался увеличить значение переменной limit на единицу, используя следующие способы, но не увеличение значения на 1

1 ) limit++


 2 ) limit = parseInt(limit) + 1;

Всегда возвращается 0 значение предельной переменной. Пожалуйста, кто-нибудь, помогите мне, что я пропустил в коде.

1 Ответ

0 голосов
/ 15 июня 2019

попробуйте поставить

var limit=0;

вне функции

jQuery(".custom_product_box_add").click(function(e){...}

Каждый раз, когда вы нажимаете предел, вы получаете ноль, но в коде нет другой ошибки, которая делает ограничение не инкрементным

Успешный обратный вызов вызывается без ошибок?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...