Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ajaxÓëxmlÊý¾Ý½»»¥

ajaxÓëxmlÊý¾Ý½»»¥
AJAX¿ÉÒÔͨ¹ýʹÓÃXMLÎļþÀ´ÈÃÐÅÏ¢²úÉú»¥¶¯
AJAX XML ʵÀý
ÔÚÏÈÃæµÄAJAXʵÀýÖÐÎÒÃǽ«ÑÝʾÈçºÎÈÃWEBÒ³ÃæʹÓÃAJAX¼¼ÊõÀ´»ñÈ¡µ½À´×ÔXMLÎļþµÄÐÅÏ¢
´ÓÏÂÀ­¿òÖÐÑ¡ÔñÒ»ÅÌCD
Ñ¡ÔñCD: Bob DylanBonnie TylerDolly Parton
TITLE: Greatest Hits
ARTIST: Dolly Parton
COUNTRY: USA
COMPANY: RCA
PRICE: 9.90
YEAR: 1982
AJAX ʵÀý½âÎö
The example above contains a simple HTML form and a link to a JavaScript:
ÉÏÃæµÄ¾ÙÀý°üº¬Á˼òµ¥µÄHTML±íµ¥ÒÔ¼°Á¬½Óµ½JSµÄlink£º
<html>
<head>
<script src="selectcd.js"></script>
</head>
<body>
<form>
Select a CD:
<select name="cds" onchange="showCD(this.value)">
<option value="Bob Dylan">Bob Dylan</option>
<option value="Bonnie Tyler">Bonnie Tyler</option>
<option value="Dolly Parton">Dolly Parton</option>
</select>
</form>
<p>
<div id="txtHint"><b>CD info will be listed here.</b></div>
</p>
</body>
</html>
As you can see it is just a simple HTML form  with a simple drop down box called "cds".
ÕýÈçÄãËù¿´µ½µÄ£¬ËüÖ»ÊǼòµ¥µÄHTML±íµ¥£¬ÀïÃæÓиöÃûΪ"cds"µÄÏÂÀ­¿ò
The paragraph below the form contains a div called "txtHint". The div is used as a placeholder for info retrieved from the web server.
ÔÚ±íµ¥ÏÂÃæµÄ¶ÎÂäÀïÓÐÒ»¸öÃûΪ"txtHint"µÄdiv¡£Ëü¿ÉÓÃÀ´ÏÔʾ´Óweb·þÎñÆ÷ÉÏ»ñÈ¡µ½µÄÐÅÏ¢
When the user selects data, a function called "showCD" is executed. The execution of the function is triggered by the "onchange" event. In other words: Each time the user change the value in the drop down box, the function showCD is called.
µ±Óû§Ñ¡ÔñÁËÐÅÏ¢£¬Ò»¸öÃûΪ"showCD"µÄº¯Êý¾Í»á±»Ö´ÐС£Õâ¸öº¯ÊýÖ´ÐÐÓë"onchange"ʼþÏà¹ØÁª¡£»»¾ä»°Ëµ£ºÃ¿µ±Óû§¸Ä±äÁËÏÂÀ­¿òÀïµÄÄÚÈÝ£¬Õâ¸öº¯Êý¾Í»áÖ´ÐС£
The JavaScript code is listed below.
JS´úÂ뽫ÔÚÏÂÃæÁгö
The AJAX JavaScript
This is the JavaScript code stored in the file "selectcd.js":
Õâ¸öÃûΪ"selectcd.js"µÄJSÎļþ±£´æÁËÎÒÃÇÇ°ÃæËù½²µ½µÄ´úÂ룺
var xmlHttp
function s


Ïà¹ØÎĵµ£º

AjaxµÄÔ­ÀíºÍÓ¦ÓÃ

¹ØÓÚajaxµÄÃû×Ö
    ajax µÄÈ«³ÆÊÇAsynchronous JavaScript and XML£¬ÆäÖУ¬Asynchronous ÊÇÒì²½µÄÒâ˼£¬ËüÓбðÓÚ´«Í³web¿ª·¢ÖвÉÓõÄͬ²½µÄ·½Ê½¡£
¹ØÓÚͬ²½ºÍÒì²½
 
Òì²½´«ÊäÊÇÃæÏò×Ö·ûµÄ´«Ê䣬ËüµÄµ¥Î»ÊÇ×Ö·û£»¶øͬ²½´«ÊäÊÇÃæÏò±ÈÌصĴ«Ê䣬ËüµÄµ¥Î»ÊÇè壬Ëü´«ÊäµÄʱºòÒªÇó½ÓÊÜ·½ºÍ·¢ËÍ·½µÄʱÖÓÊ ......

Ïê½âAJAXºËÐÄÖеÄXMLHttpRequest¶ÔÏó

 XMLHttpRequest ¶ÔÏóÊÇAJAX¹¦ÄܵĺËÐÄ£¬Òª¿ª·¢AJAX³ÌÐò±ØÐë´ÓÁ˽âXMLHttpRequest ¶ÔÏó¿ªÊ¼¡£
    Á˽âXMLHttpRequest ¶ÔÏó¾ÍÏÈ´Ó´´½¨XMLHttpRequest ¶ÔÏó¿ªÊ¼£¬ÔÚ²»Í¬µÄä¯ÀÀÆ÷Öд´½¨XMLHttpRequest ¶ÔÏóʹÓò»Í¬µÄ·½·¨£º
    ÏÈ¿´¿´IE´´½¨XMLHttpRequest ¶ÔÏóµÄ·½·¨£¨·½·¨1£©£º
va ......

дһ¸öajax funciton

function Ajax(url)
{
var m_xmlReq=null;
if(window.ActiveXObject)
{
try
{
m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e)
{
try{m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
}
}
else if(window.XMLHttpRequest ......

Ajax»ù´¡

1£ºAjax¿ÉÒÔͨ¹ýJavaScriptµÄXMLHttpRequest¶ÔÏóÓë·þÎñÆ÷½øÐÐͨÐÅ£¬Í¨¹ýXMLHttpRequest£¬JavaScript¿ÉÒÔÔÚ²»ÖØÔØÒ³ÃæµÄÇé¿öÏÂÓë·þÎñÆ÷½øÐÐͨÐÅ¡£
 
2£ºXMLHttpRequest ä¯ÀÀÆ÷Ö§³Ö
 
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
    {
xmlHtt ......

Ajax½éÉÜ XMLHttpRequest

Ajax½éÉÜ
AJAX - ä¯ÀÀÆ÷Ö§³Ö
AJAX µÄÒªµãÊÇ XMLHttpRequest ¶ÔÏó¡£²»Í¬µÄä¯ÀÀÆ÷´´½¨ XMLHttpRequest ¶ÔÏóµÄ·½·¨ÊÇÓвîÒìµÄ¡£IE ä¯ÀÀÆ÷ʹÓà ActiveXObject£¬¶øÆäËûµÄä¯ÀÀÆ÷ʹÓÃÃûΪ XMLHttpRequest µÄ JavaScript ÄÚ½¨¶ÔÏó¡£ÈçÐèÕë¶Ô²»Í¬µÄä¯ÀÀÆ÷À´´´½¨´Ë¶ÔÏó£¬ÎÒÃÇҪʹÓÃÒ»Ìõ "try and catch" Óï¾ä¡£
<script type="t ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ