programing

jQuery Ajax가 iOS에서 작동하지 않음(list.js 포함)

starjava 2023. 3. 28. 20:32
반응형

jQuery Ajax가 iOS에서 작동하지 않음(list.js 포함)

웹 사이트에서는 동작하지 않지만 iOS 기기(iPad, iPhone)에서만 동작하는 기능을 발견했습니다.

list.js를 사용하여 입력에 입력된 내용을 기반으로 디렉토리의 라이브필터링을 수행합니다.분류법에 따라 필터링할 수 있는 두 개의 선택 필드도 있습니다.이것들은 잘 작동한다.

라이브 필터링 기능은 Chrome, Firefox, Safari, IE 및 Android에서 작동합니다.디버깅을 위해 다음 작업을 수행했지만 아무 소용이 없었기 때문에 다음 디버깅을 위해 어디로 가야 할지 모르겠습니다.

  • iOS를 정지시킬 가능성이 있는 대/소문자 파일명 또는 패스가 없는지 확인.
  • iOS에서 기동하고 있는지 확인하기 위해 ajax 코드에 console.log를 추가했습니다(Safari를 통한 Web Inspector에 의한 검증).
  • Web Inspector에서 오류 또는 경고 확인(오류 없음, 경고 없음, 아무것도 없음).

다음은 main.js 파일의 코드입니다.

    var listingsArray;

    $.ajax({
        url: php_ajax_url,
        type: "POST",
        data: "action=sackville_directory_feed",
        async: false,
        success: function(results) {
            var listings = JSON.parse(results);
            listingsArray = $.map(listings, function(el) { 
              return el; 
            });
        },
        error: function() {
            console.log('Cannot retrieve data.');
        }
    });

    var directory = {};
    var directoryListings = $('.list');

    directory.renderHTML = function(z, listing){
      directoryListings.append('<div class="card card-directory col-lg-3 col-md-4 col-sm-6"><div class="directory-image" style="background-image: url(' + listing.image + ')"></div><h3 class="name">' + listing.name + '</h3><p class="description">' + listing.description + '</p><span>' + ( listing.address !== '' ? listing.address + ', ' : '') + ( listing.city_province !== '' ? listing.city_province : '') + ( listing.postal !== '' ? ', ' + listing.postal : '' ) + '</span><span>' + listing.phone + (listing.website !== '' ? ' | <a href="' + listing.website +  '">Visit Website</a>' : '') + '</span></div>');
    };

    directory.init = function(){
      directoryListings.empty();
      $.each(listingsArray, function(i, listing){
        directory.renderHTML(i, listing);
      });
    }; 

    $('.directory-filters').on('change', function(){
      var option = $(this).val();
      var label = $(this).find('option:selected').text();
      directoryListings.empty();

      if(option === 'all'){
        directory.init();
      }

      $.each(listingsArray, function(i, listing){
        if(listing.hasOwnProperty('category') && listing.category.indexOf(option) >= 0){ /* If category filter is contained within listing data */
          directory.renderHTML(i, listing);
        } else if(listing.hasOwnProperty('theme') && listing.theme.indexOf(option) >= 0){ /* If theme filter is contained within listing data */
          directory.renderHTML(i, listing);
        }
      });

      $('#current-results').html(label);
    });

    /* Get it started */
    directory.init();

    /* List JS live search */
    directory.options = {
      valueNames: [ 'name', 'description', 'category' ]
    };

    directory.directoryList = new List('directory', directory.options);

  }

Sage 스타터 테마를 사용한 Word Press 사이트입니다.php_ajax_urlbit above는 함수에서 다음을 참조합니다.php:

function assets() {
    wp_enqueue_style('sage/css', Assets\asset_path('styles/main.css'), false, null);

    $ajax_url = admin_url( 'admin-ajax.php' );

    wp_enqueue_script('sage/js', Assets\asset_path('scripts/main.js'), ['jquery'], null, true);
    wp_localize_script( 'sage/js', 'php_ajax_url', $ajax_url );
    }
    add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 100); 

저는 Ajax에 대해 잘 모르기 때문에 다음에 어디로 가야 할지 안내를 해 주셨으면 합니다.아니면, 분명히 잘못된 게 보이나요?

에러를 재현할 수 없기 때문에 가능성이 낮습니다만, 보다시피, 사이트가 HTTP 상에서 동작하고 있는 동안, admin-ajax.php의 URL은 HTTPS 아래에 있습니다.

이것을 시험해 보세요.

$ajax_url = admin_url( 'admin-ajax.php', 'http' );

언급URL : https://stackoverflow.com/questions/36551094/jquery-ajax-not-working-in-ios-with-list-js

반응형