Hi all,

I am new to ajax, meaning I know nothing what so ever of programing ajax. I want to do a simple login interface with email and password (with php), but i also want that when I press submit button it show a box with "please wait..." message (this box must slide, from the top of the page). Also this box will display errors messages such as, "invalid email or password" and so on.

Any ideas if this is possible, I heard that jquery is one of the best ajax framework out there so if you guys know any of this, please let me know. Also if there is any tutorial, so i can learn a bit of ajax i would be glad.

Thanks for the help.

9 Years
Discussion Span
Last Post by Alxandr

I have no experience with jQuery, but used mootools quiet a lot. It's not just possible, but not even that hard.

Php has the ability to send answers as json (use json_encode).

Here is some pseudo-code for the serverscripting (note, this has not been tested):

$username = $_POST['uName'];
$password = $_POST['pass'];

$responseObj = array();

if($username == 'Dani' && $password == 'Web')
      $responseObj['success'] = true;
        $responseObj['success'] = false;

echo json_encode($responseObj);

On the client you'll need some simple html:

  <div id="responseDiv">
  <div id="loginForm">
    Username: <input type="text" name="uName" /><br />
    Password: <input type="password" name="pass" /><br />
    <input type="button" value="Login" id="loginButton" />
window.addEvent('domready', function(){
var responseDiv = $('responseDiv');
var loginButton = $('loginButton');
var loginForm = $('loginForm');

// Move the responseDiv out of the screen and color it.
  position: 'absolute',
  top: -200,
  left: 200,
  'background-color': '#faa'

// Add an event to the loginButton
loginButton.addEvent('click', function()
  var myJSONRemote = new Request.JSON({
    url: 'url_to_php_script.php',
    method: 'post',
    data: loginForm.toQueryString(),
    onComplete: function(server_response){
        responseDiv.set('text', 'You successfully logged in.');
        responseDiv.tween('top', -200);
  responseDiv.tween('top', 200);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.