ÍøÒ³ÖÆ×÷WebjxÎÄÕ¼ò½é£ºAJAX - Ïò·þÎñÆ÷·¢ËÍÒ»¸öÇëÇó,ÒªÏë°ÑÇëÇó·¢Ë͵½·þÎñÆ÷£¬ÎÒÃǾÍÐèҪʹÓà open() ·½·¨ºÍ send() ·½·¨¡£
AJAX - Ïò·þÎñÆ÷·¢ËÍÒ»¸öÇëÇóÒªÏë°ÑÇëÇó·¢Ë͵½·þÎñÆ÷£¬ÎÒÃǾÍÐèҪʹÓà open() ·½·¨ºÍ send() ·½·¨¡£
open() ·½·¨ÐèÒªÈý¸ö²ÎÊý¡£µÚÒ»¸ö²ÎÊý¶¨Òå·¢ËÍÇëÇóËùʹÓõķ½·¨£¨GET »¹ÊÇ POST£©¡£µÚ¶þ¸ö²ÎÊý¹æ¶¨·þÎñÆ÷¶Ë½Å±¾µÄ URL¡£µÚÈý¸ö·½·¨¹æ¶¨Ó¦µ±¶ÔÇëÇó½øÐÐÒì²½µØ´¦Àí¡£
send() ·½·¨¿É½«ÇëÇóËÍÍù·þÎñÆ÷¡£Èç¹ûÎÒÃǼÙÉè HTML ÎļþºÍ ASP ÎļþλÓÚÏàͬµÄĿ¼£¬ÄÇô´úÂëÊÇÕâÑùµÄ£º
xmlHttp.open("GET","time.asp",true); xmlHttp.send(null);ÏÖÔÚ£¬ÎÒÃDZØÐë¾ö¶¨ºÎʱִÐÐ AJAX º¯Êý¡£µ±Óû§ÔÚÓû§ÃûÎı¾¿òÖмüÈëijЩÄÚÈÝʱ£¬ÎÒÃÇ»áÁÊý“ÔÚÄ»ºó”Ö´ÐС£
<html> <body> <script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("ÄúµÄä¯ÀÀÆ÷²»Ö§³ÖAJAX£¡"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } xmlHttp.open("GET","time.asp",true); xmlHttp.send(null); } </script> <form name="myForm"> Óû§: <input type="text" name="username" onkeyup="ajaxFunction();" /> ʱ¼ä: <input type="text" name="time" /> </form> </body> </html>ÏÂÒ»½Ú½éÉÜ "time.asp" µÄ½Å±¾£¬ÕâÑùÎÒÃÇÍêÕûµÄ AJAX Ó¦ÓóÌÐò¾Í¸ã¶¨ÁË¡£
¡¡