Jump to content

Проблема с ajax cart


Go to solution Solved by fuckmoney,

Recommended Posts

Такая проблема, подключил библиотеку jquery 3 версии, так как бустрап 4 требует свежую.

 

Теперь корзина не работает и выдает ошибку.

 

Uncaught TypeError: $(...).find(...).size is not a function

Ругается на эту строчку

 

if($(this).find('input[name=variant]:checked').size()>0)

Когда переключаю на стандартную библиотеку все работает.

 

 

// Аяксовая корзина
$('form.variants').on('submit', function(e) {
	e.preventDefault();
	button = $(this).find('input[type="submit"]');
	if($(this).find('input[name=variant]:checked').size()>0)
		variant = $(this).find('input[name=variant]:checked').val();
	if($(this).find('select[name=variant]').size()>0)
		variant = $(this).find('select').val();
	$.ajax({
		url: "ajax/cart.php",
		data: {variant: variant},
		dataType: 'json',
		success: function(data){
			$('#cart_informer').html(data);
			if(button.attr('data-result-text'))
				button.val(button.attr('data-result-text'));
		}
	});
	var o1 = $(this).offset();
	var o2 = $('#cart_informer').offset();
	var dx = o1.left - o2.left;
	var dy = o1.top - o2.top;
	var distance = Math.sqrt(dx * dx + dy * dy);
	$(this).closest('.product').find('.image img').effect("transfer", { to: $("#cart_informer"), className: "transfer_class" }, distance);	
	$('.transfer_class').html($(this).closest('.product').find('.image').html());
	$('.transfer_class').find('img').css('height', '100%');
	return false;
});

 

Link to post
Share on other sites
  • Solution
// Аяксовая корзина
$('form.variants').on('submit', function(e) {
	e.preventDefault();
	button = $(this).find('input[type="submit"]');

    //new
    if($(this).find('input[name=variant]:checked').length > 0 ) 
        variant = $(this).find('input[name=variant]:checked').val();
    if($(this ).find('input[name=variant]').length > 0 ) {
        variant = $(this).find('input[name=variant]').val();
	//new	
	$.ajax({
		url: "ajax/cart.php",
		data: {variant: variant},
		dataType: 'json',
		success: function(data){
			$('#cart_informer').html(data);
			if(button.attr('data-result-text'))
				button.val(button.attr('data-result-text'));
		}
	});
	var o1 = $(this).offset();
	var o2 = $('#cart_informer').offset();
	var dx = o1.left - o2.left;
	var dy = o1.top - o2.top;
	var distance = Math.sqrt(dx * dx + dy * dy);
	$(this).closest('.product').find('.image img').effect("transfer", { to: $("#cart_informer"), className: "transfer_class" }, distance);	
	$('.transfer_class').html($(this).closest('.product').find('.image').html());
	$('.transfer_class').find('img').css('height', '100%');
	return false;
});

.size() заменить на .length

Link to post
Share on other sites

 

// Аяксовая корзина
$('form.variants').on('submit', function(e) {
	e.preventDefault();
	button = $(this).find('input[type="submit"]');

    //new
    if($(this).find('input[name=variant]:checked').length > 0 ) 
        variant = $(this).find('input[name=variant]:checked').val();
    if($(this ).find('input[name=variant]').length > 0 ) {
        variant = $(this).find('input[name=variant]').val();
	//new	
	$.ajax({
		url: "ajax/cart.php",
		data: {variant: variant},
		dataType: 'json',
		success: function(data){
			$('#cart_informer').html(data);
			if(button.attr('data-result-text'))
				button.val(button.attr('data-result-text'));
		}
	});
	var o1 = $(this).offset();
	var o2 = $('#cart_informer').offset();
	var dx = o1.left - o2.left;
	var dy = o1.top - o2.top;
	var distance = Math.sqrt(dx * dx + dy * dy);
	$(this).closest('.product').find('.image img').effect("transfer", { to: $("#cart_informer"), className: "transfer_class" }, distance);	
	$('.transfer_class').html($(this).closest('.product').find('.image').html());
	$('.transfer_class').find('img').css('height', '100%');
	return false;
});

.size() заменить на .length

 

Благодарю

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...