Не передаются данные через ajax

228
05 апреля 2018, 12:40

На ios не работает код jquery - не передаются данные через $.ajax, на android все нормально, на PC тоже нормально.

    ( function( $ ) {

     function stringToInt(string){
        return string.match(/(\d+)/g);
     }
     $('.entry-summary .woocommerce-Price-amount').removeClass().addClass('newprice woocommerce-Price-amount'); 
     function updateProductPrice(value){
         $(".newprice").first().html("<span class='price-lable'>Preț de la: </span><span id='counter'>"+value+"</span><span class='woocommerce-Price-currencySymbol'> €</span>");
     }
     function updateProductPricePersonal(value){
         $(".ywcrbp_your_price .newprice").first().html("<span class='price-lable'>Preț de la: </span><span id='counter'>"+value+"</span><span class='woocommerce-Price-currencySymbol'> €</span>");
     }

    var _total, total, price_attribs = [];
    if ($(".ywcrbp_your_price")[0]){
    var get_price_val = $(".ywcrbp_your_price .newprice").first().text();
    }else{
     var get_price_val = $(".newprice").first().text(); 
    }

    //var price_val = get_price_val.replace(/\s/g, '');     
    var price_val = stringToInt(get_price_val); 
    //var data_price = get_price_val.substr(13,4);
    var currency = $(".woocommerce-Price-currencySymbol").first().text();
    //data_price = data_price.replace(/\s/g, '');

    var product_price_text = $('.entry-summary .newprice').first().text();
    if ($(".ywcrbp_your_price")[0]){
    var product_price_personal = $('.ywcrbp_your_price .newprice').first().text();
    var product_price = stringToInt( product_price_personal );
    }else{
    var product_price = stringToInt( product_price_text );
    }
    var size_glass_1_min = $('#size_glass_1').attr('min'); 
    var size_glass_1_max = $('#size_glass_1').attr('max');
    var size_glass_2_min = $('#size_glass_2').attr('min');
    var size_glass_2_max = $('#size_glass_2').attr('max');
    $('#size_sizes_1').attr('min', size_glass_1_min);
    $('#size_sizes_1').attr('max', size_glass_1_max);
    $('#size_sizes_2').attr('min', size_glass_2_min);
    $('#size_sizes_2').attr('max', size_glass_2_max);

    var min_size_1 = parseInt($('#size_sizes_1').attr('min'));
    var min_size_2 = parseInt($('#size_sizes_2').attr('min'));
    $('#size_sizes_1').val(min_size_1);
    $('#size_sizes_2').val(min_size_2); 
    function pSlct(){
    var efile = $('.excel_file').val(); 
     if(efile != undefined){
        if($('#fixPricesSelct').length == 0){ 
     $.ajax ({
        type: "POST",
        dataType: "json",
        url: "/wp-content/uploads/wp-excel/"+efile+".php",
        data: { size1 : 600, size2 : 600 },
          success:function(data) {
            if(data){
            var data = jQuery.parseJSON(JSON.stringify(data));
            $.each(data, function(key, value) {
            $('.product_select')
            .append($("<option></option>")
             .attr({'price': value.allp, 'value': value.nr})
              .text(value.nr+' (+€'+value.allp+')')); 
            });
            checkExtraOptions(); excel_file_option(); sizes_select();}  }
          });
        }
      }
    }
    function sizes_select(){    
      var res = [];
      if($('.product_select').length > 0){
      $('.size_glass1').attr('readonly', true);
      $('.size_glass2').attr('readonly', true);
    }
    $('.product_select option:selected').each(function(){
      var selected_select = $(this).val();
      var selected_price  = $(this).attr('price');
      res = selected_select.split("x");
      $('input[id^=selectsp_'+this.id+'').val(stringToInt(selected_price));
      $('input[id^=selectsp_'+this.id+'').attr('size1', res[0]);
      $('input[id^=selectsp_'+this.id+'').attr('size2', res[1]);
      $('#size_sizes_1').val(res[0]);
      $('#size_sizes_2').val(res[1]);
      $('input[data-id='+$(this).attr('id')+']').val('1');
     });
    }
    $("#size_sizes_1").on('change',function() {
          var max = parseInt($(this).attr('max'));
          var min = parseInt($(this).attr('min'));
          var val_1_size = $('#size_sizes_1').val();
        if(val_1_size != ''){
          if ($(this).val() > max)
          {
              $(this).val(max);
          }
          else if ($(this).val() < min)
          {
              $(this).val(min);
          }  
        }    
    }); 

    $("#size_sizes_2").on('change',function() {
          var max = parseInt($(this).attr('max'));
          var min = parseInt($(this).attr('min'));
          var val_2_size = $('#size_sizes_2').val();
        if(val_2_size != ''){ 
          if ($(this).val() > max)
          {
              $(this).val(max);
          }
          else if ($(this).val() < min)
          {
              $(this).val(min);
          }  
        }    
    }); 

function size_sizes_1(){
if($('#price_size').length > 0){
     var newSizeVal1 = $('#size_sizes_1').val();
     var newSizeVal2 = $('#size_sizes_2').val();
     if($('#size_sizes_1').length == 0 && $('#size_sizes_2').length == 0){
     var newSizeVal1 = $('input[id^=selectsp_]').attr('size1');
     var newSizeVal2 = $('input[id^=selectsp_]').attr('size2'); }
     var nfile = $('.excel_file').val(); 
     var procent = $('input[id^=procent_id_]').first().attr('procent');
     var final_price_procent;
     if(nfile != undefined){
     $.ajax ({
            type: "POST",
            dataType: "json",
            url: "/wp-content/uploads/wp-excel/"+nfile+".php",
            data: { size1 : newSizeVal1, size2 : newSizeVal2 },
            success:function(data) {
            if(data){
            var data = jQuery.parseJSON(JSON.stringify(data));
           final_price_procent = parseFloat(data[0].price) / 100 * parseFloat(procent);
           $('input[id^=procent_id_]').first().val(Math.ceil(final_price_procent));
           $('input[id^=procent_id_]').first().attr('price', Math.ceil(final_price_procent));
           $('input[id^=cheadf_procent_]').first().val(Math.ceil(final_price_procent));
           $('span[id^=check_procentaj_]').first().html('(<span>+<span class="currency-option">€</span>'+Math.ceil(final_price_procent)+'</span>)');        
           $('#price_size').val(data[0].price); checkExtraOptions();
       }else{
        $('input[id^=procent_id_]').first().val('0');
        $('input[id^=procent_id_]').first().attr('price', '0');
        $('input[id^=cheadf_procent_]').first().val('0');
        $('span[id^=check_procentaj_]').first().html('(<span>+<span class="currency-option">€</span>0</span>)'); 
        $('#price_size').val('0'); checkExtraOptions();} }
        }); 
        }else{ $('#price_size').val('0'); checkExtraOptions(); } 
    }
}
function size_sizes_2(){
if($('#price_size').length > 0){
        var newSizeVal1 = $('#size_sizes_1').val();
        var newSizeVal2 = $('#size_sizes_2').val();
        if($('#size_sizes_1').length == 0 && $('#size_sizes_2').length == 0){
         var newSizeVal1 = $('input[id^=selectsp_]').attr('size1');
         var newSizeVal2 = $('input[id^=selectsp_]').attr('size2'); }
        var nfile = $('.excel_file').val();  
        var procent = $('input[id^=procent_id_]').first().attr('procent');
        var final_price_procent;
       if(nfile != undefined){
        $.ajax ({
            type: "POST",
            dataType: "json",
            url: "/wp-content/uploads/wp-excel/"+nfile+".php",
            data: { size1 : newSizeVal1, size2 : newSizeVal2 },
            success:function(data) {
                if(data){
             var data = jQuery.parseJSON(JSON.stringify(data));     
             final_price_procent = parseFloat(data[0].price) / 100 * parseFloat(procent);
             $('input[id^=procent_id_]').first().val(Math.ceil(final_price_procent));
             $('input[id^=procent_id_]').first().attr('price', Math.ceil(final_price_procent));
             $('input[id^=cheadf_procent_]').first().val(Math.ceil(final_price_procent));
             $('span[id^=check_procentaj_]').first().html('(<span>+<span class="currency-option">€</span>'+Math.ceil(final_price_procent)+'</span>)');      
             $('#price_size').val(data[0].price); checkExtraOptions();
         }else{
         $('input[id^=procent_id_]').first().val('0');
         $('input[id^=procent_id_]').first().attr('price', '0'); 
         $('input[id^=cheadf_procent_]').first().val('0');
         $('span[id^=check_procentaj_]').first().html('(<span>+<span class="currency-option">€</span>0</span>)');   
         $('#price_size').val('0'); checkExtraOptions();} }
        }); 
       }else{ $('#price_size').val('0'); checkExtraOptions(); }
    }
}

    function excel_file_option(){
        var newSizeVal1 = $('#size_sizes_1').val();
        var newSizeVal2 = $('#size_sizes_2').val();
       $('input[class=excel_file_option]').each(function(){
        if(newSizeVal1 != '' || newSizeVal2 != ''){
        $('.price').first().attr('id', 'first_price');
        $('#first_price').attr('class', 'calculated');}
        var attr_option = $(this).attr('option');
        var nfile = $(this).val();
       if(nfile != undefined){
        $.ajax ({
            type: "POST",
            dataType: "json",
            url: "/wp-content/uploads/wp-excel/"+nfile+".php",
            data: { size1 : newSizeVal1, size2 : newSizeVal2 },
            success:function(data) {
                if(data){
                 var data = jQuery.parseJSON(JSON.stringify(data)); 
               $('#'+attr_option+'').val(data[0].price); 
               $('#'+attr_option+'').attr('price', data[0].price); 
               $('#cheadf_'+attr_option+'').val(data[0].price);
               $('#check_price_'+attr_option+'').html('(<span>+<span class="currency-option">€</span>'+data[0].price+'</span>)');
                 checkExtraOptions();
                  }else{
               $('#'+attr_option+'').val('0');
               $('#'+attr_option+'').attr('price', '0'); 
               $('#cheadf_'+attr_option+'').val('0');
               $('#check_price_'+attr_option+'').html('(<span>+<span class="currency-option">€</span>0</span>)');
                checkExtraOptions();} 
            }
        }); 
       }else{ $('#'+attr_option+'').val('0');  $('#'+attr_option+'').attr('price', '0'); checkExtraOptions(); }
         });
    }

    $('#thwepof_product_fields').remove();
    $(".currency-option").text(currency);
    $(".quantity").after('<input type="hidden" id="thisIsOriginal" name="thisIsOriginal" value="'+price_val+'"><input id="quanty" type="hidden" value="1">');
    $('.cart input[type=checkbox]').on('change', function(){
        if($(this).is(':checked')){
           $('input[data-id='+$(this).attr('id')+'').val('1');
              }else{
           $('input[data-id='+$(this).attr('id')+'').val('0');
        }
    });
    $('[class^=cart] input[type=checkbox]').each(function(){
           $('input[data-id='+$(this).attr('id')+'').val('0');
    });
    $('a[data-id]').each(function(){
        var val_src = $(this).clone();
        $("label[for="+$(this).attr('data-id')+"]").append(val_src);
        $(this).remove();
    });
    $('.cart select[class^=product_select]').each(function() {
        $('input[data-id='+$(this).attr('id')+'').val('0');
    }); 
    if ($(".ywcrbp_your_price .newprice")[0]){
    var product_price_txt = $('.entry-summary .newprice').first().text();
    var price_pers_disc = $('#thisIsOriginal').val();
    var productprice = stringToInt( product_price_txt );    
    var calc_price = parseInt(price_pers_disc) * 100 / parseInt(productprice);
    var perce_price = 100 - parseInt(Math.floor(calc_price));
    $('.cart').append('<input type="hidden" id="y_percentage" name="y_percentage" value="'+perce_price+'">');
    }

    function checkExtraOptions(){
        var final_price_checkbox = 0;
        var final_price_select = 0;
        var newFinalPrice = 0;
        var qty = $('#quanty').val();
        if($('#price_size').length > 0){
        var size_price = $('#price_size').val();
        }else{  var size_price = 0; }
        var newSizeVal1 = 0;
        var newSizeVal2 = 0;
        $('[class^=cart] input[type=checkbox]:checked').each(function(){
            if($(this).attr('price').length > 0){
            var newCheckBoxPriceValue = $(this).attr('price');}else{var newCheckBoxPriceValue = 0;}
                final_price_checkbox += parseFloat(newCheckBoxPriceValue);
              $('input[data-id='+$(this).attr('id')+']').val('1'); 
        });
        $('.cart select[class^=product_select]').each(function() {
                    var selected_select  = $("option:selected", this).text();
                    var pos = selected_select.lastIndexOf('€');
                    var newSelectBoxPriceValue = 0;
                    if (pos !== -1){
                      var selected_select_price =  selected_select.substring(pos + 1);
                      newSelectBoxPriceValue = selected_select_price;
                      final_price_select += parseFloat(newSelectBoxPriceValue);
                      $('input[id^='+this.id+'').val(stringToInt(newSelectBoxPriceValue));
                       $('input[data-id='+$(this).attr('id')+']').val('1');
                    }
                  });

             if(size_price != 0){
               if($('input[id^=selectsp_]').length > 0){ 
                   newFinalPrice = (parseFloat(final_price_checkbox) + parseFloat(final_price_select)) * qty;  }else{ newFinalPrice = (parseFloat(size_price) + parseFloat(final_price_checkbox) + parseFloat(final_price_select)) * qty; }
            }else{
                if($('.size_glass1').length > 0){ newFinalPrice = (parseFloat(final_price_checkbox) + parseFloat(final_price_select)) * qty;
                  }else{
           newFinalPrice = (parseFloat(product_price) + parseFloat(final_price_checkbox) + parseFloat(final_price_select)) * qty;
           }
        }
        if ($(".ywcrbp_your_price .newprice")[0]){ 
            updateProductPricePersonal( newFinalPrice );
              }else{
            updateProductPrice( newFinalPrice );
        }
    }
     $('.cart select[class=product_select]').change(function() {
            sizes_select();
            size_sizes_1(); 
            size_sizes_2();
            excel_file_option();
            checkExtraOptions();
      });
    $('.cart input[type=checkbox]').change(function() {
          checkExtraOptions();
      });
     $('.quantity').on('change',function(){
          checkExtraOptions();
      }); 
    $('#size_sizes_1').live('input', function() {
         excel_file_option();
         size_sizes_1();
      });
     $('#size_sizes_2').live('input', function() {
         excel_file_option();
         size_sizes_2();
      });
     $('input[id^=size_sizes_]').on('change', function() {
         excel_file_option();

      });
    /*
     * DOMready event.
     */
    $( document ).ready( function() {
        $.ajaxSetup({ cache: false });
        pSlct();
        sizes_select();
        excel_file_option();
        size_sizes_1();
        size_sizes_2();
        checkExtraOptions();
        if ( $('#wpadminbar').length ) {
            $('.home.home-5 .header-5').css('top', '60px');
        }
    });
} )(jQuery);
READ ALSO
Некорректно работает форма AJAX

Некорректно работает форма AJAX

Что не так не могу понятьФорма работает через раз и не всегда до конца

159
Не работает mysql_fetch_array

Не работает mysql_fetch_array

Есть таблица users, в ней две колонки - id и loginДля примера, первая запись - id 1, login 7433

150
Не работает ссылка после pjax?

Не работает ссылка после pjax?

Здравствуйте! На странице есть GridView обернутый в pjax с фильтрамиНа каждую запись добавлена ссылка:

181