Page 1 of 1

Updating without reloading the page

Posted: Sat Oct 15, 2005 2:03 pm
by Covenant
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Okay I'm a bit new to PHP.   

Let's say the variable 'calories' is currently 450.

Code: Select all

<?php
 if($diet == "yes")
 {
  mysql_query("UPDATE mcdonalds set calories=calories-50 where id='1'");
  $currentcal=mysql_fetch_array(mysql_query("SELECT calories from mcdonalds where id='1'"));
 echo "Now it's only <b>$currentcal[calories]</b> calories!";
 exit;
 }
 print "<a href=?diet=yes>Diet!</a>";
 ?>
How would you get it so that the calories is updated on that page? So that it says "Now it's only 400 calories!" WITHOUT RELOADING THE PAGE? Is that not possible?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Oct 15, 2005 2:14 pm
by Nathaniel
You will have to look into AJAX. Do a search for it, we've discussed it before.

Posted: Sat Oct 15, 2005 2:14 pm
by feyd
hidden iframe and/or xmlhttp/ajax are the only real options.. but it is suggested to just refresh the page..

Posted: Sun Oct 16, 2005 8:25 am
by dreamline
Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)

Posted: Sun Oct 16, 2005 9:59 am
by foobar
dreamline wrote:Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)
Newer webbrowsers have been supporting it for years. It's just that few websites actually use AJAX. It's pretty damn powerful at any rate.

Posted: Sun Oct 16, 2005 12:39 pm
by alex.barylski
dreamline wrote:Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)
Just the term AJAX used to describe the technology is new...and maybe the XMLHttp technology...

I've used techniques such as hidden IFRAMES for a long time now...

Prior to AJAX this was more commonly refered to as Javascript RPC (remote procedure calls)

This is cool stuff...but there are inherent problems...for instance...if your entire app is powered by Ajax, you loose you browsers back button functionality...a page update using AJAX doesn't register anything with the browser cache...

Most users (myself included) are very comfortable using back/forward buttons while using web apps :)

Just a reminder :)

Posted: Sun Oct 16, 2005 12:51 pm
by feyd
a few browsers do actually cache the results of requests made via AJAX...

Posted: Sun Oct 16, 2005 1:18 pm
by alex.barylski
feyd wrote:a few browsers do actually cache the results of requests made via AJAX...
Really?

Cool...which ones?

Posted: Sun Oct 16, 2005 1:20 pm
by feyd
if memory serves me, IE6 and Gecko 1.4+ based browsers do.. but don't quote me on that ;)