New poster here: just starting with PHP, slow learner, not finding what i want in online manual (prolly me, not the manual).

I've found an extremely simple js library which does exactly what I want: in "index.htm", you click on "div#1" and the text in "div#0" is updated from "text1.php"; click on "div#2", and the text is updated from "text2.php", and so on.

But I can't get it working. I think the problem is with the .php files which provide the update.

An update file esentially consists of html tags with classes and ids, which reference a separate css file called from "index.htm", eg:

<div class="longtext">
	<span class="chin L">
begin 九</span>
	<div class="section">	
        <p class="chin">
乾 元</p>
english text

What PHP needs to be added so that the file is recognised as PHP, and then the html is parsed and the css is referenced as if this were an html file?

Hi Ctoz,
I suppose that your server supports PHP (e.g. your hosting plan includes PHP). A PHP script must (under normal circumstances) be saved in a file with extension .php and the script inside of it should be wrapped in <?php and ?>.
I suggest you start with a simple PHP script to verify that PHP is working fine on your server. Save this into test.php, upload it onto your server and run it by typing its address into your browser.

echo 'Hello world';

Now that you verified that PHP is running fine do the same with text1.php. You should first see that it returns what you expect before you start using it with JavaScript.

If text1.php doesn't run add this at the top (after opening <?php) to see error messages:

ini_set("display_errors", true);

Then paste the errors here and I'll tell you what's wrong.

to inilize an action when a div is clicked, it needs to have the "onclick" parameter set.


<div class="longtext" id="div0">
	<span class="chin L">
begin 九</span></div>
	<div class="section" id="div1" onclick="javascript:getText(this.id,'div0');">	
        <p class="chin">
乾 元</p>
english text

Many thanks, both: trying to run before walking.

@petr.pavel, I've set up and tested a server offline; hadn't bothered to check host server because it's a university's, but I guess it's best to be methodical, and I hadn't tested 'test1.php' alone. Back soon.

@hunkychop, the js library uses the call "$ajaxreplace(divId [where the replacement text is to go], url [of replacing text], ecache [true or false])" , I guess I'll stick with that for the moment, and deal with one factor at time.


OK, have done as suggested: the test files are at:
on Apache/1.3.41 Server.

The files are:
hello.php, with error reporting;
insert.php, with error reporting;
test.htm, with links to both the above and to the two required javascript files:
simpleajax.js and simple.js.

Using Firefox2.0/OSX10.4:
the two .php files return plain text of the code;
with test.htm, all four links correctly fade-out the existing text, but none replaces text from the php files.

Suggestions more than welcome...

Hi Ctoz,
I'm surprised that hello.php and insert.php return the source code and not the output of the code after execution. For instance, hello.php should just output
Hello world
while insert.php should fire an error because you put ?> after HTML and not before it. So my guess is that your hosting doesn't support PHP.

But it's not the problem you're dealing with right now. Your current problem is JavaScript related (this is a PHP forum).

The JS library you have is version 0.1 beta. I was hoping to find a newer version http://simplejs.bleebot.com/ but apparently, this is the latest.

I didn't find the error. The file is difficult to read because it has no indentation so I suggest that you add it as you debug the script. Best if you install Venkman https://addons.mozilla.org/cs/firefox/addon/216 and set up a couple of break points.

Before you do, try using full url in $ajaxreplace('updatehere','hello.php',false); Instead of just 'hello.php' try 'http://www-personal.usyd.edu.au/~ctillam/tests/PHPsimpleTest/hello.php'.

Good luck.

Close to abandoning this approach : [

Can't believe a very big university's server doesn't support php, dozens of php files within the webspace: so it's me?? Do I need to get my space specifically set up for PHP?

Full filepath in js call makes no difference.

If this were a javascript forum I'd be saying,
"in http://www-personal.usyd.edu.au/~ctillam/tests/PHPsimpleTest/test.htm
on all four links, I get the same flag in Firebug:
simpleajax.js, line 46
this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");

this Object method=POST queryStringSeparator=?'

I think I'm going to look for a library that will update html with html.

Hi Ctoz, there is JS/AJAX forum here:

I don't quite understand what you posted but I noticed "ActiveXObject" - ActiveX isn't supported in Firefox unless you install some plugin (I haven't tried it).
Mozilla/Firefox uses XMLHttpRequest() for http requests from JavaScript.

simpleajax.js seems to support it so I don't know what's wrong.
I don't feel like debugging your script so you're on your own here. Really, try Venkman (see my earlier post).

Fair enough: I'm still suspecting it's me rather than the script.

Thanks for tip abt Firefox, and Venkman. All pretty new territory.



I have been struggling with those same problems with simple.js. After some debug, I've found the root of it, and how to handle it, so I thought I'd share right at this forum so I could help since I used this topic to find a solution.

The problem is in the server. Script works, but server throws a "Method not allowed" error when you try to request an ajax response using POST. This is a server configuration, it doesn't allow the page to be fetched, so that's why you see the fade out but not the expected fade in. The script does catch the error, but it's status-handling functions, like onError, has no code, so that's why you don't get any errors, it is catched but not handled.

There's two answers to this: either you configure your server to allow those POST requests (haven't tried this one), or you can easily edit the line "this.method="POST";" in simpleajax.js and change to GET. It should work fine after this.

Another source of problems can be this piece of code also in simpleajax.js:


While I was trying to make it work on my local machine, just by opening the file on Firefox, code was working fine but the "OK status", which by this code should be 200, it was in fact 0. So, changing the "if" statement to check on 0 made my page works. When I uploaded to server, "OK status" was back to 200, so as you can see, this could be a try-and-see thing.

Another problem one could have, but not related to simple.js, is wrong encoding when the new page is fetched, even when main caller HTML specifies it. Just be sure to save the .html in the desired encoding, like UTF-8. Page will be fetched with it's native encoding and not with the encoding of the caller.

Hope this helps. SimpleJS is a good lightweight library, and I was hating to dispose of it just because some simple code was not working. Many hours of reading, trying, browsing forums and sweating, I finally got it to work. It was very confusing how some people could just use the library right away, and some just couldn't. But, fortunately I was able to pinpoint the problem.

hi Mr. ctoz
It is only possible if you can implement AJAX.
if any problem in implementing ajax or if you want any idea just give me a mesg i will help you