简体   繁体   中英

AJAX script disappears after live refresh

so I've got 2 AJAX scripts and one of them disappears when the first script is fired.

Script 1:

        function myFunction<?php echo $product['sku'] ?>() {
        // AJAX CALL

          var url = "remove.php?isbn=<?php echo $product['sku'] ?>";

          $.ajax({
            url: url,
            success: function(data){
              $('#refresh').load(location.href + ' #results');
              bs4pop.notice('Το προϊόν αφαιρέθηκε με επιτυχία', {position: 'topcenter', type: 'success'});
            },
            complete: function(){

            }
            });
      };

Script 2:

  $('#insert').on('click', function () {
    var $this = $(this);
    var loadingText = '<i class="spinner-border float-right spinner-border-sm"></i> Παρακαλω Περιμενετε...';
    if ($(this).html() !== loadingText) {
      $this.data('original-text', $(this).html());
      $this.html(loadingText);
    }
    //Disable our button
    $('.btn-dis').attr("disabled", true);
    $('.checked').attr("disabled", true);

    //The URL that we are sending an Ajax request to.
    var url = "insert.php?woocommerce";

    $.ajax({
      url: url,
      success: function (data) {
        bs4pop.notice('Η εισαγωγή έγινε με επιτυχία', {
          position: 'topcenter',
          type: 'success'
        })
        $this.html($this.data('original-text'));
      },
      complete: function () {
        $('#refresh').load(location.href + ' #results');
        $('.btn-dis').attr("disabled", false);
        $('.checked').attr("disabled", false);
      }
    });
  });
     

They are both wrapped into two divs $('#refresh').load(location.href + ' #results'); , when i click the button that fires the first script the second script disappears.

What seems to be the problem?

Thank you and regards.

Ok so i got it working, i moved the button which fired the second script outside the refresh div and it worked like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM