ajax 호출 후에 스크립트를 다시 실행할 수있는 방법이 있습니까?ajax 호출 후 jquery 함수를 다시 실행하십시오.
가 나는 photoswipe이 (라이트) JQuery와 플러그인이 같은 전화 :
jQuery(document).ready(function($){
if($('.img-frame a').length > 0){
var myPhotoSwipe = $(".img-frame a").photoSwipe();
}
});
나는 또한 아약스 '로드 게시물'기능을 가지고 있고, 분명히 photoswipe가로드 된 후 이미지를 대상으로하지 않습니다 첫 번째 페이지로드.
아약스에 대한 많은 지식이 없습니까? 감사합니다
UPDATE : 나는이 방법 functions.php 워드 프레스에 전화
jQuery(document).ready(function($) {
// The number of the next page to load (/page/x/).
var pageNum = parseInt(djwd_load_posts.startPage) + 1;
// The maximum number of pages the current query can return.
var max = parseInt(djwd_load_posts.maxPages);
// The link of the next page of posts.
var nextLink = djwd_load_posts.nextLink;
/**
* Replace the traditional navigation with our own,
* but only if there is at least one page of new posts to load.
*/
if(pageNum <= max) {
// Insert the "More Posts" link.
$('#content')
.append('<div class="lp-placeholder-'+ pageNum +'"></div>')
.append('<p id="lp-load-posts" class="long-button"><a href="#">Load More Posts<i class="icon-chevron-down icon-large"></i></a></p>');
// Remove the traditional navigation.
$('#nav-below').remove();
}
/**
* Load new posts when the link is clicked.
*/
$('#lp-load-posts a').click(function() {
// Are there more posts to load?
if(pageNum <= max) {
// Show that we're working.
$(this).text('Loading posts...');
$('.lp-placeholder-'+ pageNum).load(nextLink + ' .post',
function() {
$(this).hide().fadeIn(700);
// Update page number and nextLink.
pageNum++;
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);
// Add a new placeholder, for when user clicks again.
$('#lp-load-posts')
.before('<div class="lp-placeholder-'+ pageNum +'"></div>')
// Update the button message.
if(pageNum <= max) {
$('#lp-load-posts a').text('Load More Posts');
} else {
$('#lp-load-posts a').text('No more posts to load.');
}
}
);
} else {
$('#lp-load-posts a').append('.');
}
return false;
});
});
: 다음은 '로드'더 스크립트의
function djwd_ajax_load_init() {
global $wp_query;
if(!is_singular()) {
wp_enqueue_script('ajax-load-posts', get_template_directory_uri() . '/js/ajax-load-posts.js', array('jquery'), true);
$max = $wp_query->max_num_pages;
$paged = (get_query_var('paged') > 1) ? get_query_var('paged') : 1;
wp_localize_script(
'ajax-load-posts',
'djwd_load_posts',
array(
'startPage' => $paged,
'maxPages' => $max,
'nextLink' => next_posts($max, false)
)
);
}
}
add_action('template_redirect', 'djwd_ajax_load_init');
어떻게 ajax 통화를하고 있습니까? –
코드를 함수로 옮기고 함수를'$ (document) .ready()'및 Ajax 요청 후에 호출하십시오. – Morpheus
모든 관련 코드로 질문을 편집했습니다. – djwd