Jump to content

need help in adding preloader to ajax code


doforumda

Recommended Posts

hi

i need help in adding preloader to ajax code. in the following code i want to add preloader when user clicks on Tab One and also when user enter its username and password and after pressing submit button there i want to add preloader. i have a loader.gif image so please help me how and where can i add it

loginTab.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <link rel="stylesheet" href="style.css"/>
    </head>

    <body>
        <div class="tabs" onclick="tabOne()">Tab One</div>
        <div id="message"></div>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
        <script type="text/javascript" src="script.js"></script>
    </body>
</html>

 

script.js

function tabOne() {
    $('div#message').load('login.html');
}
function login () {
    var url = 'login.php';
    var user = $('input#user').val();
    var pass = $('input#pass').val();

    var queryString = 'user=' + user + '&pass=' + pass;

    $.post(url,queryString,display);
    function display(data) {
        $("#content").html(data);
    }
}

 

login.html

<div id="content"></div>
<form>
    Username:<br />
    <input type="text" name="user" id="user" /><br />
    Password:<br />
    <input type="password" name="pass" id="pass" /><br />
    <input type="button" name="submit" id="submit" value="Login" onclick="login()" />
</form>

 

login.php

<?php
$email = strip_tags($_POST['user']);
$password = strip_tags($_POST['pass']);

//echo $email;
//echo $password;

if($email&&$password) {

    $connect = mysql_connect("localhost","user","pass");
    mysql_select_db("facebook");
    $query = mysql_query("SELECT email FROM users WHERE email='$email'");
    $count = mysql_num_rows($query);
    if($count == 0) {
        echo "You are registered thanks.";
    }
    else {
        die("That email address already exist.");
    }
}
else {
    die("please fill in both fields!");
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.