亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

AJAX? MySQL

?? ?? - MySQL ??????

? ??? ???? ?????? ???? ??? ????.

QQ截圖20161009173957.png

?? ?? - HTML ???

???? ? ???? ???? ???? ???? "showUser( "? ?????)" ??? ?????. ? ??? "onchange" ???? ?? ??????:

<html>
 <head>
     <script>
         function showUser(str)
         {
             if (str=="")
             {
                 document.getElementById("txtHint").innerHTML="";
                 return;
             }
             if (window.XMLHttpRequest)
             {
                 // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執(zhí)行代碼
                 xmlhttp=new XMLHttpRequest();
             }
             else
             {
                 // IE6, IE5 瀏覽器執(zhí)行代碼
                 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
             }
             xmlhttp.onreadystatechange=function()
             {
                 if (xmlhttp.readyState==4 && xmlhttp.status==200)
                 {
                     document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                 }
             }
             xmlhttp.open("GET","getuser.php?q="+str,true);
             xmlhttp.send();
         }
     </script>
 </head>
 <body>
 <form>
     <select name="users" onchange="showUser(this.value)">
         <option value="">Select a person:</option>
         <option value="1">Peter Griffin</option>
         <option value="2">Lois Griffin</option>
         <option value="3">Glenn Quagmire</option>
         <option value="4">Joseph Swanson</option>
     </select>
 </form>
 <br>
 <div id="txtHint"><b>Person info will be listed here.</b></div>
 </body>
 </html>

showUser() ? ??? ?? ??? ?????.

·?????????????????????????????????????????????~ ~ ~????????????????????? ?? ?? ???)

PHP ??


??? JavaScript? ?? ??? ?? ???? ??? PHP ?? "getuser.php"???.

"getuser.php"? ?? ??? MySQL ??????? ?? ??? ???? ??? HTML ???? ?????.

<?php
$q=$_GET["q"];
$con = mysqli_connect('localhost','peter','abc123','my_db');
if (!$con)
{
        die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysqli_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>";
mysqli_close($con);
?>
??: ??? JavaScript?? PHP? ???? ?? 1. PHP? MySQL ??????? ?? ??? ???.

2. ??? ???? ????.

3. HTML ???? ???, "txtHint" ?? ???? ?? ????.

???? ??
||
<html> <head> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執(zhí)行代碼 xmlhttp=new XMLHttpRequest(); } else { // IE6, IE5 瀏覽器執(zhí)行代碼 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select> </form> <br> <div id="txtHint"><b>Person info will be listed here.</b></div> </body> </html>