View Full Version : Dynamic Ajax Content with Galleria

06-13-2013, 08:13 PM
1) Script Title: Dynamic Ajax Content

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

3) Describe problem:

Fellow coders,

I am getting a little desperate here, I ask for your help.

Here's the situation:

I use a tree-like submenu for my page, which has multiple levels and I wanted them to stay "as is" if the user navigates. Obvious solution was to use the formentioned DD script. Although it works wonderfully, my problem is that the ajax loaded page uses a jquerry gallery (namely, Galleria). Now it may seem like it's working OK but it's not - although I use an onclick event to start galleria when loading the ajax content, if you click a menu twice, it disappears - I think the most likely solution is because the gallery script does not load again. I am not sure though. I tried with loadobj() function as well, did not work either, as it only loads the script once - a second click on the active menu and it falls apart again.

Please check out for yourselves, I set up a demo page here (http://solyomattila.extra.hu/tg/index.php?page=termekek). Click the second menu, "Asztali áru", only these submenus work for the purpose of testing.

I welcome any suggestions; thank you in advance.

06-13-2013, 09:35 PM
It works fine on my machine except for the very first page load. After a page refresh, there's no problem anymore.

06-14-2013, 03:27 AM
It looks like you need to remove this code:

<script type="text/javascript">
if (document.cookie.indexOf('visited=true') === -1) {
var expires = new Date();
document.cookie = "visited=true; expires="+expires.toUTCString();

$("a[rel='welcomehun']").colorbox({transition:"fade", open:"true",
scrolling:false, innerWidth:480, innerHeight:385, opacity:.5});

because if the cookie isn't present, it tries to load colorbox, which isn't there, so it ends up throwing an error and other scripts (like the accordion) don't work as expected. That's why on reload (after the cookie is set) the accordion works.

Now on to the AJAX issue. I'm surprised it works at all like that. Here's what to do. Forget about loadobjs, you can load any scripts or styles that you want in the head of the page in the normal manner with external script tags and stylesheet links. Use this version of the script which removes loadobjs and adds a success function argument:

function ajaxpage(url, containerid, success){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
catch (e){
page_request = new ActiveXObject("Microsoft.XMLHTTP")
catch (e){}
return false
loadpage(page_request, containerid, success)
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)

function loadpage(page_request, containerid, success){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
if(typeof success == 'function'){

Then instead of doing this:

<a href="javascript:ajaxpage('HUN/termekek/kehely02.php', 'contentarea');" onClick="Galleria.run('#galleria2');">Vitrum et Anima</a>


<a href="HUN/termekek/kehely02.php" onclick="ajaxpage(this.href, 'contentarea', function(){Galleria.run('#galleria2');}); return false;">Vitrum et Anima</a>

The browser cache may need to be cleared and/or the page refreshed to see changes.

06-14-2013, 08:54 AM
Oh god, I can't say how happy I am right now. Thank you John, it works perfectly!