Я хотел бы увеличить значение переменной на единицу при успешном вызове 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
значение предельной переменной.
Пожалуйста, кто-нибудь, помогите мне, что я пропустил в коде.