View Full Version : Ajax tabs breaks php variables

04-26-2009, 12:45 PM
1) Script Title: Ajax Tabs Content Script (v 2.2)

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

3) Describe problem:

Hi all, I'm implementing languages on a website I manage. All the text is called from a single page by echoing variables. Everything works fine for everything outside the 'div id="content"' container which is the dynamic ajax tabs. The weird thing is, if you view the source of the page, the text is actually there, but just not visible or formatted into the browser. If I comment out the ajax script it shows fine. I tried changing the 'content' variable incase it conflicted with another, but same thing happens.

The testimonial and request form tabs work as they are not echoed variables, just normal text.



04-26-2009, 02:24 PM
PHP is interpreted first by the server, but only if the page has the .php extension. If the page you are importing doesn't have that extension, it will appear as garbage, a comment, or otherwise be ignored - depending upon the browser.

Now, this may not be what is happening here, but before we go any further, we must be sure that the imported PHP content is being parsed by the server as PHP.

04-26-2009, 03:09 PM
Hi John,

Thanks for your help. PHP will be imported with whatever extension it's assign in apache. In this case yes, everything is imported fine. The entire site relies on PHP and all the text you can see are variables that are working. If you view source in your browser, you will see the main body text is there as well, but not visible when the page loads. If I comment out the ajax-tabs.js script the text loads fine, but obviously the tabs stop working.


04-26-2009, 03:29 PM
If I ask the browser what it thinks it was served I get:

<DIV id="content"><P><? echo $company['p1'];?></P>

<P><? echo $company['p2'];?></P>

<IMG src="/images/staff_tj.jpg" alt="Tatjana John" class="thumb_pics">

<P><? echo $company['p3'];?></P>

<P><? echo $company['p4'];?></P>

So, I am assuming that the PHP tokens are only getting resolved by the server when it serves the source view at the browser's request.

I'd double check that the external files have the .php extension. It can't hurt anything.

04-26-2009, 03:33 PM
If you want to see what is being sent by the server in response to the AJAX request, temporarily edit this function in ajaxtabs.js (add the highlighted):

ddajaxtabs.loadpage=function(page_request, pageurl, tabinstance){
var divId=tabinstance.contentdivid
document.getElementById(divId).innerHTML=ddajaxtabssettings.loadstatustext //Display "fetching page message"
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
ddajaxtabs.ajaxpageloadaction(pageurl, tabinstance)

04-26-2009, 04:14 PM
Hi John,

I see what your saying after I did your trick. All the files are .php but the content files are .inc which are pulled into index.php. I just tried changing them to .php but the same thing happens, except with the javascript pop up you see the same content, minus the php code. Why does the content still load when you view the source though? Any other ideas?

04-26-2009, 04:16 PM
This is what I see with a .php extension.



<img src="/images/staff_tj.jpg" alt="Tatjana John" class="thumb_pics" />



Again though, it's loaded in the background, very strange.

04-27-2009, 10:00 AM
Anymore ideas John / anyone else?

04-27-2009, 01:21 PM
Well, I'm not really sure. I just tried a test on a PHP enabled server. I downloaded the archive ajaxtabscontent.zip (http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/ajaxtabscontent.zip) from Dynamic Drive. I renamed all the files in its root folder to .php and then did a global search and replace on those files:




and added:

$testvar = 'Bob';
echo $testvar;

to external5.php (4rth tab in the second all AJAX demo from demo.php)

I then uploaded the entire demo to the server. The PHP was resolved fine when clicking the tab for that page.

So I guess I am wondering if you really renamed your external files to .php and called them by their new names to the main page, or if you simply made copies and were still calling the old .inc versions?

Or perhaps your 'top' page was cached by the browser and was still calling the old versions.

In any case, on your demo page, they are still called as .inc.

<ul id="menu_items" class="shadetabs">
<li class="null"><a href="javascript:void(0);" rel="#default"></a></li>
<li><a href="/include/company-profile.inc" rel="content" class="selected">profile</a></li>
<li><a href="/include/services.inc" rel="content">services</a></li>
<li><a href="/include/testimonials.inc" rel="content">testimonials</a></li>
<li><a href="/include/request-form.inc" rel="content">request form</a></li>
<li><a href="/include/contacts.inc" rel="content">contacts</a></li>

04-27-2009, 05:20 PM
Hi John,

Ya, seems like it should work without problem and I'm sure it's something simple, but I'm not seeing it. I had changed all my local files to .php, but not online. I just changed them all, every single file is .php and is referenced as such. The testimonials tab works but that is just txt in the external file. Seems that the script is not translating the PHP in those files. Not sure if it helps, but my structure is that header.php, body.php, and footer.php are all called from the main index.php file, with the content loaded from external .php files based on the requested link. Anything else I can do to troubleshoot?


04-27-2009, 05:43 PM
I think I figured out the problem. I tried putting a simple echo test in the php file and it worked (should have tried that to start). It's not reading my language file for the variables even though it's working on the rest of the pages. The index.php file references the language file and a search path, however the standalone external files have no idea where this file is since they are just loaded into the structure. Any suggestions on how I can make the path global for even those? It has to be a variable and not fixed in each external file.


04-27-2009, 05:50 PM
My PHP is not the best. But if you were to make it a session variable, that might work. Also, since the server will parse whatever PHP code is on the external pages as it is fetching them, if you put the variable on each external page, valid for their locations in your folder structure, it should work.

04-27-2009, 05:59 PM
Good idea, I'll create a session variable for it. Thanks for all your help and speedy replies!