TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-22-2007, 10:32 PM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
Gurnk's Avatar
 
Join Date: Oct 2007
Location: US
Posts: 66
Thanks: 19
Gurnk is on a distinguished road
Default A Few AJAX Questions

Hey. I just have a few general questions about AJAX, as I am thinking about adding a little to my site. So here they are.

I have all my stuff stored in a database, is it easy to update info from a database and not have to reload the page. i.e click a link and it updates a section with the new database stuff. If it is, do you have any example code you could throw my way? Thanks.

EDIT: Also, is it possible to keep all this AJAX (the stuff mentioned above) on the same page, so I don't have to include external files. I've seen some things that might have worked, but they had to post stuff to another file.

Um... Just 1 I guess. :p Thanks guys.
Send a message via MSN to Gurnk
Gurnk is offline  
Reply With Quote
Old 10-22-2007, 11:08 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

To answer them in order! It's definitely possible to have it update your database without reloading. As for an example, really you'll want to download the popular Javascript framework, Prototype, and give that a whirl with its AJAX features. As well as all the other features it has to offer! It's really easy to use with AJAX. It will give you plenty of examples on the Prototype website.

You don't really have to include external files anyway - just your external Javascript file, although technically this could also be incorporated in your PHP file - just not very coder-friendly. The PHP file that you call when you make your AJAX call can also feasibly be the same file you make the call from - it's just you'll have to configure it a different route of execution for when the page loads when you're accessing it via AJAX as to when you normally access it - you can do this by setting a URL parameter, for instance. However, I load separate files to make the code more easy to manage.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-22-2007, 11:10 PM   #3 (permalink)
The Contributor
Upcoming Programmer 
 
Gurnk's Avatar
 
Join Date: Oct 2007
Location: US
Posts: 66
Thanks: 19
Gurnk is on a distinguished road
Default

Thanks for the quick reply Wildhoney. I'll definitely check Prototype out. I've seen you guys talking about it on the boards before, and was thinking about checking it out anyway.
Send a message via MSN to Gurnk
Gurnk is offline  
Reply With Quote
Old 10-23-2007, 02:03 AM   #4 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

I agree with Wildhoney on using prototype. Before I knew that existed, I was doing AJAX the old fashioned way and I hated it! So much code, and it's not guaranteed to work on all browsers, which is a real hassle.

A simple AJAX call in Prototype is very simple:

Code:
function updateForm(element) {
  new Ajax.Request({
    parameters: Form.serialize(element)
  });
}
Which you'd use with an onsubmit attribute

Code:
onsubmit="updateForm(this); return false"
Make sure the form has an ID, otherwise it won't work.

This is pretty useless code, but it gives somewhat of an idea on how simple it is.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 10-23-2007, 11:30 AM   #5 (permalink)
The Contributor
Upcoming Programmer 
 
Gurnk's Avatar
 
Join Date: Oct 2007
Location: US
Posts: 66
Thanks: 19
Gurnk is on a distinguished road
Default

That is simple. :)
Send a message via MSN to Gurnk
Gurnk is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:59 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design