Jump to content

Using Javascript To Change Php Include Page?


kensbeijing

Recommended Posts

Is it possible to use javascript to decide which page to include() in php?I have a row of 4 links, each link should change the include() page (in php) of a page without having to reload. So i need something like this:

<a title="link 1" onclick="<?php include('page1.php') ?>"><a title="link 2" onclick="<?php include('page2.php') ?>"><a title="link 3" onclick="<?php include('page3.php') ?>"><a title="link 4" onclick="<?php include('page4.php') ?>">

If you see what I mean...But most importantly I need it to not have to reload the page, and be able to keep changing page when you press the button.Thanks.

Link to comment
Share on other sites

AJAX will be the solution, but I am not good at it, so others will need to assist you here.javascript by itself will not parse the php include file. It is client-side only.

Link to comment
Share on other sites

jl is correct. And I recall your asking about AJAX, so I'll assume some of that stuck. As you describe, a user clicks on a link or something, and that sets the AJAX process in motion. Javascript sends a request based on what the user clicked. The targeted PHP script grabs the corresponding file and echoes it. Back on the client browser, the AJAX callback function gets the file data in AJAX.responseText, and assigns it to some element's innerHTML.FWIW, I've been working on a series of AJAX demos. (Not quite ready for prime time.) This one has more than you want, but the "quotes" section exactly illustrates the kind of thing you mean.http://www.sophox.com/sophox/ajax/sampler.htmlRelevant source files in human readable-form:http://www.sophox.com/sophox/ajax/demo.php.txthttp://www.sophox.com/sophox/ajax/poe.php.txt

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...