Обновите старый код AJAX до текущей версии JQUERY

0

У меня есть старый код AJAX, который работает в JQuery 1.8.3, но не работает с более поздними версиями. Поскольку я пытаюсь обновить свой код и стараюсь избегать устаревшего кода, мне нужно обновить свой скрипт.

Текущий код

$('.productlist input[type=submit]').bind('click', function () {
  var i = 0;
  var a = $(this).closest('.productlist2').find('input[data-productid][value!=]').length;
  $(this).closest('.productlist,.WPproductlist').find('input[data-productid][value!=]').each(function () {
      if ($(this).attr('data-produktfarve') != "") {
          $.ajax({
              url: '?ProductID=' + $(this).attr('data-productid') + '&EcomOrderLineFieldInput_farvevalg=' + $(this).attr('data-produktfarve') + '&Quantity=' + parseFloat($(this).val()) + '&cartcmd=add',
              success: function (data) {
                  i++;
                  if (i == a) {
                      window.location.reload();
                  }
              }
          });
      } else {
          $.ajax({
              url: '?ProductID=' + $(this).attr('data-productid') + '&Quantity=' + parseFloat($(this).val()) + '&cartcmd=add',
              success: function (data) {
                  i++;
                  if (i == a) {
                      window.location.reload();
                  }
              }
          });
      }
  });
  setTimeout(function () {
      window.location.reload();
  }, 500);
  return;
});

Я пробовал с различными новыми версиями JQUERY получить и отправить запрос, но безрезультатно.

Теги:
jquery-post

1 ответ

0

Попробуй это,

$(function(){
    $('.productlist input[type=submit]').on('click', function () {
       var i = 0;
       var a = $(this).closest('.productlist2')
                      .find('input[data-productid][value!=""]').length;
       $(this).closest('.productlist,.WPproductlist')
              .find('input[data-productid][value!=""]').each(function () {
          var myurl = '?ProductID=' + $(this).data('productid');
          if ($(this).data('produktfarve') != "") {
              myurl+='&EcomOrderLineFieldInput_farvevalg='+$(this).data('produktfarve');
          }
          var qty=this.value;
          $.ajax({
              url: myurl+ '&Quantity=' + parseFloat(qty) + '&cartcmd=add',
              success: function (data) {
                  i++;
                  if (i == a) {
                      window.location.reload();
                  }
              }
          });
       });
       setTimeout(function () {
          window.location.reload();
       }, 500);
       return;
    });
});

Ещё вопросы

Сообщество Overcoder
Наверх
Меню