2013-10-08 2 views
0

내가 주요 내용을로드 Ajax를 사용하여 사이트를 가지고 있고, 나는 .load()이 완료된 후 함수 (afterLoad)를 실행하려면 다음 코드를 사용하고 완료 ..지연 기능은

jQuery('.main-menu a').click(function(evt){ 
     var href = jQuery(this).attr('href'); 
     var elementClassName = jQuery(this).attr('class'); 
     History.pushState({}, '', href); 

     jQuery('.content').load(href+ ' #main',afterLoad); 
      function afterLoad() { 
       jQuery('.content').fadeIn(750); 
       if (document.location.pathname == "/works/") { 
        jQuery(function($){ window.dzsp_init("#port0",{ 
         settings_slideshowTime:3 
         ,settings_mode: "masonry" 
         ,title: "" 
         ,design_item_width: "" 
         ,design_item_height: "" 
         ,design_categories_style: "normal" 
         ,design_categories_pos: "top" 
         ,design_pageContent_pos: "top" 
         ,settings_disableCats: "off" 
         ,settings_lightboxlibrary: "zoombox" 
         ,settings_preloadall: "off" 
         ,audioplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/ap.swf" 
         ,videoplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/preview.swf" 
         ,disable_itemmeta: "off" 
         ,settings_ajax_loadmoremethod: "button" 
         ,settings_mode_masonry_layout: "masonry" 
         ,design_total_height_full: "off" 
         ,settings_mode_masonry_layout_straightacross_setitemsoncenter: "off" 
         ,design_item_height_same_as_width : "off"}) 
        }); 
       } 
      } 
     return false; 
    }); 

모든 것이 잘 작동하지만 때로는 afterLoad이 실행되어 .load()이 완료되기 전에 실행됩니다. 어쨌든 afterLoad을 지연 시켜서 모든 것이로드되기 전에로드가 완료되었는지 확인하십시오. 인수 인 경우

+0

행운이 문제를 해결하려면? – lukeocom

+0

외부 파일에 함수를 배치하고 콜백에서 .getscript를 호출했습니다. – SBM

답변

0

호출 스크립트의 끝

뭔가

$.ajax({ url: 'script.php?argument=value&foo=bar' }); 

또는

$('#result').load('ajax/test.php'); 

추천하고 함수의에서 JQuery와의 PHP 함수 할 체크를 확인합니다 선물이 있다면 건너 뛰십시오.