View Full Version : 2 questions regarding the use of Dynamic Ajax Content

10-26-2009, 11:23 AM
1) Script Title: Dynamic Ajax Content

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

3) Describe problem:
a) the first problem is regarding the load of PHP pages into a div by using this script. I've read a lot of topics on this matter and it seems that other encountered this as well, but I've also seen that some people successfully used this script with php pages. I'm trying something simple here, a contact form with a submit button (the page phptest.php to be loaded in the "content" div):

<a href="javascript:ajaxpage('phptest.php', 'content');">Pag php</a>

The problem is that after clicking on the "Pag php" button the div "content" remains empty. It seems that the PHP code is not executed. Is there a sort of limitation of this script regarding the PHP pages or am I missing something else in the code?

b) the second problem is actually a question regarding the same script. I have a menu made with javascript. Is there any method to perform 2 actions when a button is clicked? What I mean exactly: when I click on "Home" button I want to fully reload the index.html page (not in the "content" div) and then to load in the "content" div the page 'test.html'. Is this possible in any way but just click only once on a button? The code for a button is the same like the line described at point a).

Any suggestions are welcomed!
Thank you in advance.

10-26-2009, 02:29 PM
For your first question, the served HTML of the PHP must be valid HTML, and the page you are importing it to may need to be PHP. Also, any paths on the PHP page should be absolute. The PHP page must be on the same domain as the page you are importing it to, and must look this way to the browser. PHP must be enabled on the server, and there may be no restrictions set in PHP's configuration on its use that may hinder the import process. There could be other issues.

As to your second question, in general yes - as many operations as desired may be carried out onclick of an element. In this particular case though, once the page is reloaded, any further activity via javascript must be carried out onload or as the page loads in the browser. If you have a PHP enabled server, this could be assisted by PHP by passing a query value to the page (but the index would have to be PHP). Javascript itself can retrieve a query value and carry out an action on the reloaded page, ex:

<script type="text/javascript">
function getQval(n, m) {
/*my n=name, m=searchString(optional)*/
if(!arguments[0]||typeof n!='string')
return null;
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=arguments[1]?m:location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
if(getQval('queryName') === 'expectedQueryValue')
window.onload = function(){
ajaxpage('test.htm', 'contentarea');

So let's say you want to pass test as the query value for p. All you need is a normal link:

<a href="index.htm?p=test">Index w/test</a>

Then in the above code, where I have:

if(getQval('queryName') === 'expectedQueryValue')

Make it like so:

if(getQval('p') === 'test')

If you want more help:

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