ajax 再次调用,在ajax调用后再次运行jquery函数

在ajax调用之后再次运行脚本有什么方法吗?在ajax调用后再次运行jquery函数

我有一个photoswipe(灯箱)的jQuery插件我这样调用:

jQuery(document).ready(function($){

if($('.img-frame a').length > 0){

var myPhotoSwipe = $(".img-frame a").photoSwipe();

}

});

我也有一个AJAX“加载更多信息”功能,显然photoswipe不针对后装图片首页加载。

我没有太多的Ajax知识,对此有什么帮助?由于

更新:这里的 '负载更多的' 脚本:

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('

.append('

Load More Posts

');

// 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('

// 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;

});

});

我把它在WordPress的functions.php中这样说:

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');

2012-12-14

djwd

+3

你打算怎么做ajax调用? –

+0

将你的代码移动到'$(document).ready()'中调用该函数,并在ajax请求后调用 –

+0

我编辑了所有相关代码的问题 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值