PDA

View Full Version : Dynamic Ajax Content and Pretty Photo



mylo
03-27-2011, 03:40 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:

Hi there,

I got a problem regarding the loading of the PrettyPhoto script (http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/). It works perfectly the first time opened but after using the navigation the script is not running anymore..

Is there a way to reload it?

Many thanks in advance..

tuibm
03-27-2011, 06:57 PM
I have exactly the same problem, not with Pretty Photo, but with other 2 javascritps... first time work then it works sometimes and sometimes no... if u find a solution let me know :)

mylo
03-28-2011, 02:23 PM
Yeah, seems to be a usual problem.
I somehow need to re-initialize prettyPhoto every time I load new picture through ajax. But got no idea how to do that or where to add the code..

jscheuer1
03-28-2011, 02:39 PM
If Pretty Photo is reasonably well written, and you 're using:


<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
</script

to initialize it in the first place, edit this part of the AJAX script:


function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

to:


function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;
$("a[rel^='prettyPhoto']").prettyPhoto();
}
}

If you're using a different initialization, use the corresponding part of it there instead.

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.

As a side note - jQuery has robust AJAX routines, so you should consider using it for the AJAX part, save some overhead on loading the page. But doing so might require some custom coding and an understanding of jQuery AJAX functions, unless you can find a jQuery AJAX plugin that's easily adaptable to your purposes.

mylo
03-29-2011, 07:39 AM
John you're great!

I had to modify a bit but it works now!

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;
$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'dark_rounded',slideshow:4000, autoplay_slideshow: false});
}
}

thank you very much!

ola_la_beautifull
09-17-2011, 02:26 AM
I have a website aittech.vn/demo/joomla/joomla15_test/index.php?option=com_rokquickcart&view=rokquickcart&Itemid=2, when you click : Your Cart: (x items), it loading prettyPhoto (pwd.js). It works perfectly the first time opened but after click to increase product in prettyPhoto then not increase the number of products. :(