For example the explanation-the H tml form
As you can see, this is just a simple HTML format for the dropdown box called "User" name and "id" from the database, as a choice of value.
The following form of the paragraph contains the so-called "Txthint" of a zone. The zone is a network server that is used as a location for reservation information retrieval.
When the user selects the data, a function called "showuser ()" executes. The function performed is the "onchange" event that is raised.
In other words: each change in the value of the user in the dropdown box, function Showuser () is invoked.
The JavaScript
This is the JavaScript code stored in the file "Selectuser.js":
var xmlHttp
function Showuser (str)
{
xmlhttp=getxmlhttpobject ()
if (xmlhttp==null)
{
alert ("Browser does Not support HTTP Request "]
return
}
var url=" getuser.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 | | xmlhttp.readystate== "complete")
{
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;
}
For example
the statechanged () and Getxmlhttpobject functions are the same as PHP's AJAX chapters suggest that you can go there to explain these.
The Showuser () function
If an item is selected in the Drop-down box to perform the following function:
calls Getxmlhttpobject function to create a XMLHTTP object
defines the URL (file) to be transmitted to the server
Add a parameter (Q) to the URL with the content of the dropdown box
to add a random number to prevent the server from using the cache file
Call StateChanged When the change is triggered
opening XMLHTTP object with a specific URL.
Send an HTTP request to the server
PHP page
The server's page requirements for JavaScript, is a simple php file named "getuser.php".
The Web page is written in PHP and uses a MySQL database.
The code runs a database of SQL queries and returns the result as an HTML table:
<?php $q =$_get["Q"];
$con = mysql_connect (' localhost ', ' Peter ', ' abc123 ');
if (! $con) {die (' could not connect: '. Mysql_error ());
} mysql_select_db ("Ajax_demo", $con);
$sql = "SELECT * FROM user WHERE id = '". $q. "'";
$result = mysql_query ($sql); echo "<table border= ' 1 ' > <tr> <th>Firstname</th> <th>Lastname</th> <th>age
</th> <th>Hometown</th> <th>Job</th> </tr> ";
while ($row = Mysql_fetch_array ($result)) {echo "<tr>"; echo "<td>". $row [' FirstName '].
"</td>"; echo "<td>". $row [' LastName '].
"</td>"; echo "<td>". $row [' Age '].
"</td>"; echo "<td>". $row [' Hometown '].
"</td>"; echo "<td>". $row [' Job '].
"</td>";
echo "</tr>";
echo "</table>"; Mysql_close ($con)?> reprint please indicate from Http://www.111cn.net/wy/yw.html