...

View Full Version : Dynamically Updating PHP Using JavaScript?



KodiTiger
12-27-2010, 04:19 AM
I've done some googling and have come across some information, but I'm not quite sure how to apply it to my problem.

I have a PHP page saturna.php with six frames on it using the frameset commands. I would like to somehow make it so that when I click on something in one frame (with one PHP page loaded in it - game.php), it automatically/dynamically updates one of the other PHP pages (inventory.php) in another frame. What will happen is when the thing is clicked on in game.php, an entry will be added to the database, and the second PHP page (which retrieves information from the database) will notice that there is a new relevant record, and will add it to the inventory.php page in the table I have constructed there.

From my googling it seems I need to use JavaScript to do this, but I'm not quite sure how - any ideas :) ?

Thanks very much!

tfburges
12-27-2010, 05:28 AM
I'll start off by saying it's probably best to not use frames... but I have a feeling switching over to a dynamic div layout would be too much of a pain and take too long at this point... but it would be worth it.

That said, I'll focus on how to do it with frames. You'll need to use AJAX and wait for the response from the server to make sure the database has been updated before reloading the other frame. More specifically, the javascript that calls the AJAX function should call another function upon response... and this other function will target the other frame via javascript's DOM (dynamic object model) and reload its location. Something like... top.nameoftheframetoreloadhere.location.reload();
If you google things like "ajax example" and "javascript reload frame" you should get plenty of helpful results.

KodiTiger
12-27-2010, 01:08 PM
I'll start off by saying it's probably best to not use frames... but I have a feeling switching over to a dynamic div layout would be too much of a pain and take too long at this point... but it would be worth it.

That said, I'll focus on how to do it with frames. You'll need to use AJAX and wait for the response from the server to make sure the database has been updated before reloading the other frame. More specifically, the javascript that calls the AJAX function should call another function upon response... and this other function will target the other frame via javascript's DOM (dynamic object model) and reload its location. Something like... top.nameoftheframetoreloadhere.location.reload();
If you google things like "ajax example" and "javascript reload frame" you should get plenty of helpful results.

Can you (or someone else) explain how to do the dynamic div layout thing? I know how div tags work, I've made a similar page using div tags just now. How can I solve my problem using this div layout? Thanks!

tfburges
12-28-2010, 05:40 AM
It's kind of long and complicated... your best bet is to do a search for something like "ajax innerhtml"... I'm sure there are plenty of tutorials out there on the subject.

http://www.google.com/search?q=ajax+innerhtml+examples



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum