Process information without refreshing the page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MonsieurRenard
Forum Newbie
Posts: 5
Joined: Sun Jun 11, 2006 2:45 pm

Process information without refreshing the page?

Post by MonsieurRenard »

Imagine a simple scenario in which the user enters any string into a textbox, presses submit, and the string is printed back out just below.

The only way I know how to do that right now is that the entire page refreshes, and sends the use back at the closest anchor, which is annoying.

Is there a way to get around that. I've been told something about DOM, will that do it? Are there any books on the matter?

Thank you very much for helping out a noobie, I plan on making an extended stay here since I will be working with PHP all summer :).
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

AJAX springs to mind :P
MonsieurRenard
Forum Newbie
Posts: 5
Joined: Sun Jun 11, 2006 2:45 pm

Post by MonsieurRenard »

Ah yes, that went through my mind at one point.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Thats about the only way to perform the actions you require... 8)
MonsieurRenard
Forum Newbie
Posts: 5
Joined: Sun Jun 11, 2006 2:45 pm

Post by MonsieurRenard »

I'll definetly look into it, thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Process information without refreshing the page?

Post by Christopher »

MonsieurRenard wrote:Imagine a simple scenario in which the user enters any string into a textbox, presses submit, and the string is printed back out just below.
You don't need to do Ajax or to submit to a server to do that -- just Javascript. Call a function on the form submit event that sets the inner HTML of some element in your page with a value of a form field.
(#10850)
MonsieurRenard
Forum Newbie
Posts: 5
Joined: Sun Jun 11, 2006 2:45 pm

Post by MonsieurRenard »

Maybe I used a bad example. Potentially I want to be able to have an interface with independent "objects" on the page, like in GMAIL, which uses AJAX.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Right, but much of what Gmail does is Javascript managing the presentation of the application. It occasionally makes calls back to the server -- as necessary.
(#10850)
MonsieurRenard
Forum Newbie
Posts: 5
Joined: Sun Jun 11, 2006 2:45 pm

Post by MonsieurRenard »

Oh. :)

Thanks for this info, I think I'm going to need to reconsider how I'm going to make this work.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

If you don't need anything too complex, javascript is best for this. If you actually need to fetch information back from the server depending on the user's choice, then you can't do this with simple javascript, you would need AJAX. If you are just taking information that has already been loaded to the page, or are adding database/server independent objects to the page, javascript will work just fine.
Sathi
Forum Newbie
Posts: 5
Joined: Mon Jun 12, 2006 11:53 am

Post by Sathi »

I found this tutorial made sense to me when nothing else did for an initial introduction

http://rajshekhar.net/blog/archives/85- ... orial.html
Post Reply