PDA

View Full Version : Question about Ajax Tabs Content Script



alsab
05-02-2010, 02:56 PM
Hello,

I have a question about Ajax Tabs Content Script (http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/index.htm)


On my site I use for the moment the script Dynamic Ajax Content (http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm), with this link for to load an external page:


<a href="javascript:ajaxpage('../index.php?option=com_sobi2&sobi2Task=sobi2Details&sobi2Id=28&Itemid=&tmpl=component&lang=fr&print=1','essaitab');">mypage</a>

I have no problem but, if I want to use the same url with ajaxtabcontent it doesn't work:


<li><a href="../index.php?option=com_sobi2&sobi2Task=sobi2Details&sobi2Id=28&Itemid=&tmpl=component&lang=fr&print=1'" rel="countrycontainer">mypage</a></li>

I get this message:

Illegal variable _files or _env or _get or _post or _cookie or _server or _session or globals passed to script.

If I use an url like this /blabla.js for to open a file, it's ok.

So I would like to know if it's possible to load an external page like with ajaxcontent, because I don't want to use iframe?

Thanks

jscheuer1
05-03-2010, 09:45 AM
That error message looks like a PHP thing. But it could be some difference(s) between the two scripts that's causing it.

What browser are you using? If you use Firefox or can, it makes diagnosing this a little easier.

Basically the two scripts send the request in the same manner, but there are differences. The tab script massages the URL with a javascript regular expression replace to make it a "ajaxfriendlyurl" before passing it on to the server. The script you 'like' does not. And the tab script gets its url directly from the link's href property. The other script does so too, in a way, but as a string fed to the javascript:ajaxpage() function where, presumably the browser would be less likely to alter it. A raw href value is often augmented to an absolute path if it is relative (which yours is) and certain characters may be more or less likely to be escaped.

Anyways, here's where the Dynamic Ajax Content script sends its request to the server:


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)
page_request.send(null)

Make that (temporarily for diagnostic purposes):


if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
alert(url+bustcacheparameter);
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)

The tab script does it here (in ajaxtabs.js, around line #47):


var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)}
if (ddajaxtabssettings.bustcachevar) //if bust caching of external page
bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
page_request.send(null)

Make that, again temporarily for diagnosis:


var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)}
if (ddajaxtabssettings.bustcachevar) //if bust caching of external page
bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
alert(ajaxfriendlyurl+bustcacheparameter);
page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
page_request.send(null)

If it is some difference between how the scripts are processing the URL, it should become apparent when you run each of these alerts. The reason that Firefox would make this easier is that, unlike some other browsers, it allows you to cut and paste from the alert, which makes it easier for you to report any significant findings here.

Let me know what happens.

alsab
05-03-2010, 12:50 PM
Hello jscheuer1, thank you.
I found the problem with your help.
I had the same problem with Dynamic Ajax content script, but there is a long time ago. :o

There is just need to replace: & by ?


bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

by


bustcacheparameter=(url.indexOf("?")!=-1)? "?"+new Date().getTime() : "?"+new Date().getTime()



And now it's ok.

I hope, there will be no problem with this solution. What do you think?

jscheuer1
05-03-2010, 03:17 PM
If it works, I guess. But looking closely at that code, it's wrong either way. For the content script it should be:


bustcacheparameter = (url.indexOf("?") > -1? "&" : "?") + "bustcacheparameter=" + new Date().getTime();

For the tab script:


bustcacheparameter = (ajaxfriendlyurl.indexOf("?") > -1? "&" : "?") + "bustcacheparameter=" + new Date().getTime();

The two are essentially the same. In the tab script we are working from the massaged "ajaxfriendlyurl" variable. That's the only difference.

The way it was originally would result in a URL like (using your example - the actual number would be different each time):


. . . mid=&tmpl=component&lang=fr&print=1&23458193

With your modification:


. . . mid=&tmpl=component&lang=fr&print=1?23458193

Neither of which is a valid URL as far as I know. I guess PHP is better able to ignore the second one. But since the purpose of this is to prevent the page from being cached for if it gets requested a second time, if that's not an issue, you should turn it off in the configuration. If it is an issue, you should probably use my modification which results in a valid URL:


. . . mid=&tmpl=component&lang=fr&print=1&bustcacheparameter=23458193