php - jQuery plugin not working on ajax-loaded page - Stack Overflow

I am using jquery prettyPopin in one of my projects and it is working fine ... Problem is i want it to

I am using jquery prettyPopin in one of my projects and it is working fine ... Problem is i want it to work on the php page loaded using ajax. But it does not seem to work ...

My question in short is whether a jQuery plugin works in a ajax-loaded page as it does on the parent page? To make it clear my JS libraries are added in the parent page. No libraries are added in the loading script.

Do the jQuery plugins work on the ajax pages ? Also, i do not want to include js libraries in ajax page.

Any help is wele ... Thanx in advance ...

I am using jquery prettyPopin in one of my projects and it is working fine ... Problem is i want it to work on the php page loaded using ajax. But it does not seem to work ...

My question in short is whether a jQuery plugin works in a ajax-loaded page as it does on the parent page? To make it clear my JS libraries are added in the parent page. No libraries are added in the loading script.

Do the jQuery plugins work on the ajax pages ? Also, i do not want to include js libraries in ajax page.

Any help is wele ... Thanx in advance ...

Share Improve this question asked Jan 2, 2012 at 8:03 xmaestroxmaestro 1,1243 gold badges18 silver badges44 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2

any jquery plugin will work in ajax loaded pages as well. but if you are trying to call it in ajax loaded page, you need to call plugin after ajax pleted.

Yes it does work, but you have to initialize any plugins after the page has been loaded. Example when using .load():

$("#page").load("/page.php", function(response, status, xhr) {
    $('#selector-on-loaded-page').plugin();
});

You just have to include the plugin as usual on the main page.

There may be a jQuery conflict you can use your code like this

var $jq = jQuery.NoConflict();
$jq("#page").load("/page.php", function(response, status, xhr) {
    $jq('#selector-on-loaded-page').plugin();
});

It should work because the included js can be used on the loaded DOM and the included js.

Yet, it depends on how the plugin works and how you are calling it. For instance, it will likely not work if it gets dynamically applied onload or if you tried to wrap it inside your $(document).ready() of your main code.

[EDIT] According to the doc of the plugin:

Don't forget to apply the plugin again for instance, you have to put:

$("a[rel^='prettyPopin']").prettyPopin();

in the callback of your .load() statement.

So lets say you are using the plugin "foo" this way :

$(".something").foo();

in the end of the ajax request (once you get the data back from php and create the new elements) re-write the same line $(".something").foo();

another way would be to figure out how to integrate live in the way you use the plugin

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745602660a4635493.html

相关推荐

  • php - jQuery plugin not working on ajax-loaded page - Stack Overflow

    I am using jquery prettyPopin in one of my projects and it is working fine ... Problem is i want it to

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信