View Single Post
  #2 (permalink)  
Old 01-16-2008, 12:54 PM
BigAlReturns's Avatar
BigAlReturns BigAlReturns is offline
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

Hi JL, I don't have time this second to give you much code for this, but let me explain the concept of Ajax, which might help you understand the issue a bit better.

Firstly we have a page the user sees - call it news.html. This contains a form with the email field. When it's submitted, javascript functions take over, and instead of going to the form processing page as normal, JS requests the processing page in the background, so the user doesn't see anything. For our example, when submitted, JS will request the page process.php?email=whatevertypedin. Process.php is then parsed by the server as it normally would be, and outputs whatever it outputs. This output is not to your users screen though, it's back to the JS function on the original page. In true Ajax (Asynchronous javascript and XML) the output is XML, but to start with I find it easier to use a variant AJAX, which I christen AJAP, or Asynchronous Javascript And Plain-text. So in our scenario, process.php returns one of a set of values to the JS function in plain text, for example, 1 might represent not in DB, added OK. 2 means already in DB, 3 means not in DB, but error occurred adding, 4 means invalid email address
The JS function then uses this returned value to do something - for example, if 1 is returned, display a success message to the user. I'm sure you can work out suitable things to display for the other return values.

This is the basic process of how Ajax works - there is some specific code you need to use, and when I get a chance later on I'll post it for you, with some explanation of what each part of it does. Hope that helps.
Reply With Quote