S
S
strify_252018-11-14 09:45:28
JavaScript
strify_25, 2018-11-14 09:45:28

Why is fancybox 3 ajax not working on reclick?

Hello. There is a regular html link with data parameters changing in it:

<a href="#" class="askPriceBtn" data-product="Yeti 51003" data-id="10062">Узнать стоимость</a>

The parameters change correctly, there are no problems with this. When you click on this button, fancybox ajax should fire, which passes these parameters to the php script:
$('.askPriceBtn').on('click', function(event) {
    event.preventDefault();

    $.fancybox.open({
      src: '/includes/askPriceForm.php?id=' + $(this).data('id') + "&iblock=" + $(this).data('iblock'),
      type: 'ajax',
      opts : {
        afterShow : function( instance, current ) {
          $('[type="checkbox"]').iCheck({checkboxClass: 'icheckbox_square-red'});
        }
      }
    })
  });

Works correctly the first time. But then those parameters that worked for the first time are transferred to the script. I tried this option with parameter passing:
$('.askPriceBtn').on('click', function(event) {
    event.preventDefault();

    $.fancybox.open({
      src: '/includes/askPriceForm.php',
      type: 'ajax',
      ajax: {
        type: 'GET',
        data: {
          ...
        }
      }
      opts : {
        afterShow : function( instance, current ) {
          $('[type="checkbox"]').iCheck({checkboxClass: 'icheckbox_square-red'});
        }
      }
    })
  });

Also, instead of .on('click', function(event){}) I just tried .click(), the same.
Why doesn't it work and how to do it right?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question