< Buzzing or vibrating the login form using jquery Posted On May 15, 2012 : 0 comments << >> Simple div slideshow using jquery Posted On May 9, 2012 : 0 comments << >> Copy mysql column in varchar to type date Posted On May 3, 2012 : 0 comments << >> Enter only numbers inside a input field of a form using javascript Posted On May 1, 2012 : 0 comments << >> Slide in and out animate div vertically using jquery Posted On April 25, 2012 : 1 comment << >> Tag cloud using php, mysql and ajax with filter Posted On April 24, 2012 : 0 comments << >> Change webpage font color or background color from the user side using javascript Posted On April 19, 2012 : 0 comments << >> A single link that cycles through several webpage background color using javascript Posted On April 17, 2012 : 0 comments << >> Simple webpage redirection using perl script Posted On April 10, 2012 : 0 comments << >> Get ipaddress using perl script Posted On April 4, 2012 : 0 comments << >>

Ajax Page With PHP

This Tutorial Has Been Viewed 12,319 Times.
VN:F [1.9.17_1161]
Rating: 5.0/10 (1 vote cast)

The AJAX HTML Page

This is the HTML page. It contains a simple HTML form and a link to a JavaScript.

First Name:

<input type="text" id="txt1" onkeyup="showHint(this.value)"/>
<p>Suggestions: <span id="txtHint"></span></p>

The JavaScript code is listed below.
The AJAX JavaScript

This is the JavaScript code, stored in the file “clienthint.js”:

var xmlHttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="tutorialz.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

The AJAX Server Page -PHP

There is no such thing as an AJAX server. AJAX pages can be served by any internet server.

AJAX PHP Example

The code in the “tutorialz.php” page just checks an array of names and returns the corresponding names to the client:

Note: Code below is tutorialz.php
PHP Example

// Fill up array with names
$a[]="Google";
$a[]="Yahoo";
$a[]="Hotmail";
$a[]="Java";
$a[]="PHP";
$a[]="Asp";
$a[]="Ajax";
$a[]="Javascript";
$a[]="Ruby";
$a[]="Ecllipse";
$a[]="Dreamweaver";
$a[]="Flash";
$a[]="Photoshop";
$a[]="Fireworks";
$a[]="Flex";
$a[]="hass";
$a[]="marcelo";
$a[]="luciano";
$a[]="thiago";
$a[]="pallero";
$a[]="mozin";
$a[]="angush";
$a[]="gary";
$a[]="mike";
$a[]="perotti";
$a[]="michael";
$a[]="angelo";
$a[]="remoiv";
$a[]="asne";
$a[]="jack";

//get the q parameter from URL
$q=$_GET["q"];

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
echo $response;
VN:F [1.9.17_1161]
Rating: 5.0/10 (1 vote cast)

Ajax Page With PHP, 5.0 out of 10 based on 1 rating

Incoming search terms:





You will also be interested in ,

Tags: ,

16 Responses

  1. barry says:

    nice website keep going….

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  2. Coitiaday says:

    hmm wooww

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  3. elepayNah says:

    yup..

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  4. kayacLedyes says:

    good one..

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  5. kayacLedyes says:

    A good website with good inputs….hats off

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  6. keseabavero says:

    a coool……..site

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  7. AdvaddyNawn says:

    HMM

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  8. seagfuepe says:

    best of its kind

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  9. drardyDrurb says:

    a nice one..

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  10. uttequete says:

    fine

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  11. uttequete says:

    not bad..

    VA:F [1.9.17_1161]
    Rating: 5.0/5 (1 vote cast)
  12. http://community.fitnessanywhere.com/members/vbest12.aspx – christina milian nude christina milian nude

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  13. patric says:

    a nice one

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  14. salma hayek nude says:

    Good ajax stuff and php

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  15. wan says:

    cool site

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  16. googlaaa says:

    maudg3 http://google.com

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks