Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   конкатенировать строк с переменой (https://javascript.ru/forum/misc/80731-konkatenirovat-strok-s-peremenojj.html)

Hovik 22.07.2020 19:36

конкатенировать строк с переменой
 
Здравствуйте, я хочу отправит 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

Hovik 22.07.2020 20:53

здесь использую функцию
$('.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);

			}
		}
	});

Nexus 22.07.2020 22:08

Hovik, точку с запятой удалите в 12-й строке:
product +' textarea');
и фигурные скобки в 6 и 13-й строках.

laimas 22.07.2020 22:23

Hovik,

$(product +' input[type=\'text\'], '+
product +' input[type=\'hidden\'], '+
.....

и что в итоге будет, что вы пытаетесь отправить?


Часовой пояс GMT +3, время: 19:39.