конкатенировать строк с переменой
Здравствуйте, я хочу отправит ajax запрос с динамическими данными
написал функцию и через аргумент хочу отправлять разные дани вот функция function product_add( product ) { $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'POST', dataType: 'json', data: { $(product +' input[type=\'text\'], '+ product +' input[type=\'hidden\'], '+ product +' input[type=\'radio\']:checked, '+ product +' input[type=\'checkbox\']:checked, ' + product +' select, ' + product +' textarea'); }, }).done(function (res) { console.log(res) }) }; выдает ошибку Unexpected token |
здесь использую функцию
$('.buttons-buy button').on('click',function (e) { if ($(this).is('button')) { let default_val = +$(this).parent().find('input[name=quantity]').attr('value'); let count = +$(this).parent().find('input[name=quantity]').val(); let product_id = $(this).parent().find('input[name=product_id]').val(); if ($(this).hasClass('quantity-minus')) { if ($(this).next('input').val() > default_val ) { count --; } $(this).next('input').val(count) } else if( $(this).hasClass('quantity-plus') ){ count ++; $(this).prev('input').val(count) } else if ($(this).hasClass('add_product')) { product_add( $(this).parents('.product') ); $(this).parent().find('input[name=quantity]').val(default_val); } } }); |
Hovik, точку с запятой удалите в 12-й строке:
product +' textarea'); и фигурные скобки в 6 и 13-й строках. |
Hovik,
$(product +' input[type=\'text\'], '+ product +' input[type=\'hidden\'], '+ ..... и что в итоге будет, что вы пытаетесь отправить? |
Часовой пояс GMT +3, время: 19:39. |