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

PHP ?? - AJAX ??? ??

AJAX? ????? ?? ???? ??? ?? ??? ?????.


AJAX ??? ??

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

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

· ???? ???? ???? ??? ?????.

· ???? ???? ??? ? , ?? ???

· ??? ?? ??? ??? ???? ? ?? ??? ????

1.png

? ??? ??? XML ??(links.xml)?? ?????.

Instance

? ???? ???? ??? ???? "showResult()"? ?????. ??. ? ??? "onkeyup" ???? ?? ?????:

<!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>PHP中文網(wǎng)(php.cn)</title>
     <script>
     function showResult(str)
     {
     if (str.length==0)
     {
     document.getElementById("livesearch").innerHTML="";
     document.getElementById("livesearch").style.border="0px";
     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("livesearch").innerHTML=xmlhttp.responseText;
     document.getElementById("livesearch").style.border="1px solid #A5ACB2";
     }
     }
     xmlhttp.open("GET","livesearch.php?q="+str,true);
     xmlhttp.send();
     }
     </script>
 </head>
 <body>
 
 <form>
     <input type="text" size="30" onkeyup="showResult(this.value)">
     <div id="livesearch"></div>
 </form>
 </body>
 </html>

?? ?? ??:

?? ??? ?? ?? ??(str.length == 0), ? ??? ??? ?? ?? ???? ??? ??? ??? ?????.

?? ??? ?? ?? ??? showResult()? ?? ??? ?????.

· XMLHttpRequest ?? ??

· ?? ?? ???

· ??? ?? ??? ?? ???

· URL ?? ??? ????(q)? ?????(?? ?? ??) box)


XML ??

rreee

PHP ??

? ??? JavaScript? ?? ?????. ?? ???? "livesearch.php"?? PHP ?????.

"livesearch.php"? ?? ??? XML ???? ?? ???? ???? ??? ???? ??? ?????.

<pages>
    <link>
        <title>HTML DOM alt Property</title>
        <url>
            http://php.cn/htmldom/prop_img_alt.asp
        </url>
    </link>
    <link>
        <title>HTML DOM height Property</title>
        <url>
            http://php.cn/htmldom/prop_img_height.asp
        </url>
    </link>
    <link>
        <title>HTML a tag</title>
        <url>http://php.cn/tags/tag_a.asp</url>
    </link>
    <link>
        <title>HTML br tag</title>
        <url>http://php.cn/tags/tag_br.asp</url>
    </link>
    <link>
        <title>JavaScript Date() Method</title>
        <url>http://php.cn/jsref/jsref_date.asp</url>
    </link>
    <link>
        <title>JavaScript anchor() Method</title>
        <url>http://php.cn/jsref/jsref_anchor.asp</url>
    </link>
</pages>

JavaScript? ???? ??? ??(?: strlen($q ) > 0),

· XML ??? ? XML DOM ??? ?????.

· JavaScript?? ??? ???? ???? ???? ?? ?? ?? <title>

· "$response" ??? ??? URL? ??? ?????. ???? ??? ? ? ?? ???? ?? ?? ??? ??? ?????.

· ???? ??? ??? $response ??? "?? ??"?? ?????.

???? ?? ??:

3.png


???? ??
||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP中文網(wǎng)(php.cn)</title> <script> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; 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("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <input type="text" size="30" onkeyup="showResult(this.value)"> <div id="livesearch"></div> </form> </body> </html>