﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-qileilove-文章分类-AJAX</title><link>http://www.blogjava.net/qileilove/category/54306.html</link><description>不想做屌丝的码农，不是好项目经理！屌丝生涯从此开始！</description><language>zh-cn</language><lastBuildDate>Fri, 25 Apr 2014 13:24:14 GMT</lastBuildDate><pubDate>Fri, 25 Apr 2014 13:24:14 GMT</pubDate><ttl>60</ttl><item><title>AJAX 数据库实例</title><link>http://www.blogjava.net/qileilove/articles/412930.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 25 Apr 2014 05:58:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412930.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412930.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412930.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412930.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412930.html</trackback:ping><description><![CDATA[<h1><div style="display: inline-block;"><div id="intro" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; font-weight: normal; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">AJAX 可用来与数据库进行动态通信。</span></p></div></div></h1><h2 style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px;">AJAX 数据库实例</h2><h1><div style="display: inline-block;"><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; font-weight: normal; line-height: normal; background-color: #f9f9f9;"><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面的例子将演示网页如何通过 AJAX 从数据库读取信息：</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请在下面的下拉列表中选择一个客户：</p><form action="http://www.w3school.com.cn/ajax/ajax_database.asp" style="margin: 15px 0px 0px; padding: 0px; border: 0px;"><label style="margin: 0px; padding: 0px; border: 0px;">请选择一位客户：&nbsp;<select name="customers" style="margin: 15px 0px 0px; padding: 0px; border-color: #bebebe; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; height: 25px;">&nbsp;<option value="APPLE" style="margin: 0px; padding: 0px; border: 0px;">Apple Computer, Inc.</option>&nbsp;<option value="BAIDU " style="margin: 0px; padding: 0px; border: 0px;">BAIDU, Inc</option>&nbsp;<option value="Canon" style="margin: 0px; padding: 0px; border: 0px;">Canon USA, Inc.</option>&nbsp;<option value="Google" style="margin: 0px; padding: 0px; border: 0px;">Google, Inc.</option>&nbsp;<option value="Nokia" style="margin: 0px; padding: 0px; border: 0px;">Nokia Corporation</option>&nbsp;<option value="SONY" style="margin: 0px; padding: 0px; border: 0px;">Sony Corporation of America</option>&nbsp;</select></label></form><div id="txtHint" style="margin: 15px 0px 0px; border: 0px; width: 710px; color: #0479a7; font-weight: bold;">客户信息将在此处列出。</div><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_database" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一下源代码</a></p></div></div></h1><h2 style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px;">实例解释 - showCustomer() 函数</h2><h1><div style="display: inline-block;"><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; font-weight: normal; line-height: normal; background-color: #f9f9f9;"><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">当用户在上面的下拉列表中选择某个客户时，会执行名为 "showCustomer()" 的函数。该函数由 "onchange" 事件触发：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">function showCustomer(str)
{
var xmlhttp;
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE7+, Firefox, Chrome, Opera, Safari</span>
  xmlhttp=new XMLHttpRequest();
  }
else
  {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE6, IE5</span>
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getcustomer.asp?q="+str,true);
xmlhttp.send();
}
</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">showCustomer() 函数执行以下任务：</p><ul style="margin: 10px 0px 0px 35px; padding: 0px; border: 0px;"><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">检查是否已选择某个客户</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">创建 XMLHttpRequest 对象</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">当服务器响应就绪时执行所创建的函数</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">把请求发送到服务器上的文件</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">请注意我们向 URL 添加了一个参数 q （带有输入域中的内容）</li></ul></div></div></h1><h2 style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px;">AJAX 服务器页面</h2><h1><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; font-weight: normal; line-height: normal; background-color: #f9f9f9;"><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">由上面的 JavaScript 调用的服务器页面是 ASP 文件，名为 "getcustomer.asp"。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">用 PHP 编写服务器文件也很容易，或者用其他服务器语言。请看<a href="http://www.w3school.com.cn/php/php_ajax_database.asp" title="PHP 和 AJAX MySQL 数据库实例" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">用 PHP 编写的相应的例子</a>。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">"getcustomer.asp" 中的源代码负责对数据库进行查询，然后用 HTML 表格返回结果：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">&lt;% response.expires=-1 sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID=" sql=sql &amp; "'" &amp; request.querystring("q") &amp; "'"  set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs=Server.CreateObject("ADODB.recordset") rs.Open sql,conn  response.write("&lt;table&gt;") do until rs.EOF   for each x in rs.Fields     response.write("&lt;tr&gt;&lt;td&gt;&lt;b&gt;" &amp; x.name &amp; "&lt;/b&gt;&lt;/td&gt;")     response.write("&lt;td&gt;" &amp; x.value &amp; "&lt;/td&gt;&lt;/tr&gt;")   next   rs.MoveNext loop response.write("&lt;/table&gt;") %&gt;</pre></div></h1><img src ="http://www.blogjava.net/qileilove/aggbug/412930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-25 13:58 <a href="http://www.blogjava.net/qileilove/articles/412930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX ASP/PHP 请求实例</title><link>http://www.blogjava.net/qileilove/articles/412929.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 25 Apr 2014 05:55:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412929.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412929.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412929.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412929.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412929.html</trackback:ping><description><![CDATA[<div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">AJAX 用于创造动态性更强的应用程序。</span></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>AJAX ASP/PHP 实例</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面的例子将为您演示当用户在输入框中键入字符时，网页如何与 web 服务器进行通信：</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请在下面的输入框中键入字母（A - Z）：</p><form action="http://www.w3school.com.cn/ajax/ajax_asp_php.asp" style="margin: 15px 0px 0px; padding: 0px; border: 0px;">姓氏：<input id="txt1" type="text" style="margin: 15px 0px 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px; border: 1px solid #bebebe; font-family: 'Courier New', Courier, monospace; font-size: 12px; height: 30px;" /></form><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">建议：</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_suggest" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一下源代码</a></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>实例解释 - showHint() 函数</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">当用户在上面的输入框中键入字符时，会执行函数 "showHint()" 。该函数由 "onkeyup" 事件触发：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">function showHint(str) { var xmlhttp; if (str.length==0)   {   document.getElementById("txtHint").innerHTML="";   return;   } if (window.XMLHttpRequest)   {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE7+, Firefox, Chrome, Opera, Safari</span>   xmlhttp=new XMLHttpRequest();   } else   {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE6, IE5</span>   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   } xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)     {     document.getElementById("txtHint").innerHTML=xmlhttp.responseText;     }   } xmlhttp.open("GET","gethint.asp?q="+str,true); xmlhttp.send(); } </pre><h3>源代码解释：</h3><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果输入框为空 (str.length==0)，则该函数清空 txtHint 占位符的内容，并退出函数。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果输入框不为空，showHint() 函数执行以下任务：</p><ul style="margin: 10px 0px 0px 35px; padding: 0px; border: 0px;"><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">创建 XMLHttpRequest 对象</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">当服务器响应就绪时执行函数</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">把请求发送到服务器上的文件</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">请注意我们向 URL 添加了一个参数 q （带有输入框的内容）</li></ul></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>AJAX 服务器页面 - ASP 和 PHP</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">由上面的 JavaScript 调用的服务器页面是 ASP 文件，名为 "gethint.asp"。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面，我们创建了两个版本的服务器文件，一个用 ASP 编写，另一个用 PHP 编写。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>ASP 文件</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">"gethint.asp" 中的源代码会检查一个名字数组，然后向浏览器返回相应的名字：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">&lt;% response.expires=-1 dim a(30) <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">'用名字来填充数组</span> a(1)="Anna" a(2)="Brittany" a(3)="Cinderella" a(4)="Diana" a(5)="Eva" a(6)="Fiona" a(7)="Gunda" a(8)="Hege" a(9)="Inga" a(10)="Johanna" a(11)="Kitty" a(12)="Linda" a(13)="Nina" a(14)="Ophelia" a(15)="Petunia" a(16)="Amanda" a(17)="Raquel" a(18)="Cindy" a(19)="Doris" a(20)="Eve" a(21)="Evita" a(22)="Sunniva" a(23)="Tove" a(24)="Unni" a(25)="Violet" a(26)="Liza" a(27)="Elizabeth" a(28)="Ellen" a(29)="Wenche" a(30)="Vicky"  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">'获得来自 URL 的 q 参数</span> q=ucase(request.querystring("q"))  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">'如果 q 大于 0，则查找数组中的所有提示</span> if len(q)&gt;0 then   hint=""   for i=1 to 30     if q=ucase(mid(a(i),1,len(q))) then       if hint="" then         hint=a(i)       else         hint=hint &amp; " , " &amp; a(i)       end if     end if   next end if  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">'如果未找到提示，则输出 "no suggestion"</span> <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">'否则输出正确的值</span> if hint="" then   response.write("no suggestion") else   response.write(hint) end if %&gt; </pre></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>PHP 文件</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面的代码用 PHP 编写，与上面的 ASP 代码作用是一样的。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-weight: bold;">注释：</span>如需在 PHP 中运行这个例子，请将 url 变量的值（Javascript 代码中）由 "gethint.asp" 改为 "gethint.php"。</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">&lt;?php <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// 用名字来填充数组</span> $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; $a[]="Liza"; $a[]="Elizabeth"; $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky";  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">//获得来自 URL 的 q 参数</span> $q=$_GET["q"];  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">//如果 q 大于 0，则查找数组中的所有提示</span> if (strlen($q) &gt; 0)   {   $hint="";   for($i=0; $i&lt;count($a); $i++)     {     if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))       {       if ($hint=="")         {         $hint=$a[$i];         }       else         {         $hint=$hint." , ".$a[$i];         }       }     }   }  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// 如果未找到提示，则把输出设置为 "no suggestion"</span> <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// 否则设置为正确的值</span> if ($hint == "")   {   $response="no suggestion";   } else   {   $response=$hint;   }  <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">//输出响应</span> echo $response; ?&gt;</pre></div><img src ="http://www.blogjava.net/qileilove/aggbug/412929.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-25 13:55 <a href="http://www.blogjava.net/qileilove/articles/412929.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX - onreadystatechange 事件</title><link>http://www.blogjava.net/qileilove/articles/412928.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 25 Apr 2014 05:54:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412928.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412928.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412928.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412928.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412928.html</trackback:ping><description><![CDATA[<div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>onreadystatechange 事件</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">当请求被发送到服务器时，我们需要执行一些基于响应的任务。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">每当 readyState 改变时，就会触发 onreadystatechange 事件。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">readyState 属性存有 XMLHttpRequest 的状态信息。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面是 XMLHttpRequest 对象的三个重要的属性：</p><table style="margin: 10px 0px 0px; padding: 0px; border-style: solid; border-color: #aaaaaa; border-collapse: collapse; width: 709.0908813476563px;"><tbody style="margin: 0px; padding: 0px; border: 0px;"><tr style="margin: 0px; padding: 0px; border: 0px;"><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5; width: 156.36363220214844px;">属性</th><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5;">描述</th></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">onreadystatechange</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">存储函数（或函数名），每当 readyState 属性改变时，就会调用该函数。</td></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">readyState</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;">存有 XMLHttpRequest 的状态。从 0 到 4 发生变化。</p><ul style="margin: 20px; padding: 0px; border: 0px; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;">0: 请求未初始化</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;">1: 服务器连接已建立</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;">2: 请求已接收</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;">3: 请求处理中</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;">4: 请求已完成，且响应已就绪</li></ul></td></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">status</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;">200: "OK"</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">404: 未找到页面</p></td></tr></tbody></table><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">在 onreadystatechange 事件中，我们规定当服务器响应已做好被处理的准备时所执行的任务。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">当 readyState 等于 4 且状态为 200 时，表示响应已就绪：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)     {     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;     }   } </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_async_true" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-weight: bold;">注释：</span>onreadystatechange 事件被触发 5 次（0 - 4），对应着 readyState 的每个变化。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>使用 Callback 函数</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">callback 函数是一种以参数形式传递给另一个函数的函数。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果您的网站上存在多个 AJAX 任务，那么您应该为创建 XMLHttpRequest 对象编写一个<span style="margin: 0px; padding: 0px; border: 0px; font-weight: bold;">标准</span>的函数，并为每个 AJAX 任务调用该函数。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">该函数调用应该包含 URL 以及发生 onreadystatechange 事件时执行的任务（每次调用可能不尽相同）：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">function myFunction() { loadXMLDoc("ajax_info.txt",function()   {   if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)     {     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;     }   }); } </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_callback" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><img src ="http://www.blogjava.net/qileilove/aggbug/412928.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-25 13:54 <a href="http://www.blogjava.net/qileilove/articles/412928.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX - 服务器响应</title><link>http://www.blogjava.net/qileilove/articles/412840.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 23 Apr 2014 08:04:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412840.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412840.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412840.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412840.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412840.html</trackback:ping><description><![CDATA[<div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>服务器响应</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如需获得来自服务器的响应，请使用 XMLHttpRequest 对象的 responseText 或 responseXML 属性。</p><table style="margin: 10px 0px 0px; padding: 0px; border-style: solid; border-color: #aaaaaa; border-collapse: collapse; width: 709.0908813476563px;"><tbody style="margin: 0px; padding: 0px; border: 0px;"><tr style="margin: 0px; padding: 0px; border: 0px;"><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5; width: 156.36363220214844px;">属性</th><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5;">描述</th></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">responseText</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">获得字符串形式的响应数据。</td></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">responseXML</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">获得 XML 形式的响应数据。</td></tr></tbody></table></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>responseText 属性</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果来自服务器的响应并非 XML，请使用 responseText 属性。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">responseText 属性返回字符串形式的响应，因此您可以这样使用：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">document.getElementById("myDiv").innerHTML=xmlhttp.responseText;</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_async_true" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>responseXML 属性</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果来自服务器的响应是 XML，而且需要作为 XML 对象进行解析，请使用 responseXML 属性：</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请求&nbsp;<a href="http://www.w3school.com.cn/example/xmle/books.xml" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">books.xml</a>&nbsp;文件，并解析响应：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlDoc=xmlhttp.responseXML; txt=""; x=xmlDoc.getElementsByTagName("ARTIST"); for (i=0;i&lt;x.length;i++)   {   txt=txt + x[i].childNodes[0].nodeValue + "&lt;br /&gt;";   } document.getElementById("myDiv").innerHTML=txt; </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_responsexml" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><img src ="http://www.blogjava.net/qileilove/aggbug/412840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-23 16:04 <a href="http://www.blogjava.net/qileilove/articles/412840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX - 服务器响应</title><link>http://www.blogjava.net/qileilove/articles/412750.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Apr 2014 10:25:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412750.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412750.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412750.html</trackback:ping><description><![CDATA[<div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>服务器响应</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如需获得来自服务器的响应，请使用 XMLHttpRequest 对象的 responseText 或 responseXML 属性。</p><table style="margin: 10px 0px 0px; padding: 0px; border-style: solid; border-color: #aaaaaa; border-collapse: collapse; width: 709.0908813476563px;"><tbody style="margin: 0px; padding: 0px; border: 0px;"><tr style="margin: 0px; padding: 0px; border: 0px;"><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5; width: 156.36363220214844px;">属性</th><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5;">描述</th></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">responseText</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">获得字符串形式的响应数据。</td></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">responseXML</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">获得 XML 形式的响应数据。</td></tr></tbody></table></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>responseText 属性</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果来自服务器的响应并非 XML，请使用 responseText 属性。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">responseText 属性返回字符串形式的响应，因此您可以这样使用：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">document.getElementById("myDiv").innerHTML=xmlhttp.responseText;</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_async_true" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>responseXML 属性</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果来自服务器的响应是 XML，而且需要作为 XML 对象进行解析，请使用 responseXML 属性：</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请求&nbsp;<a href="http://www.w3school.com.cn/example/xmle/books.xml" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">books.xml</a>&nbsp;文件，并解析响应：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlDoc=xmlhttp.responseXML; txt=""; x=xmlDoc.getElementsByTagName("ARTIST"); for (i=0;i&lt;x.length;i++)   {   txt=txt + x[i].childNodes[0].nodeValue + "&lt;br /&gt;";   } document.getElementById("myDiv").innerHTML=txt; </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_responsexml" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><img src ="http://www.blogjava.net/qileilove/aggbug/412750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-21 18:25 <a href="http://www.blogjava.net/qileilove/articles/412750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX - 向服务器发送请求</title><link>http://www.blogjava.net/qileilove/articles/412739.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Apr 2014 06:09:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412739.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412739.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412739.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412739.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412739.html</trackback:ping><description><![CDATA[<div id="intro" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">XMLHttpRequest 对象用于和服务器交换数据。</span></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>向服务器发送请求</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如需将请求发送到服务器，我们使用 XMLHttpRequest 对象的 open() 和 send() 方法：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","test1.txt",true); xmlhttp.send(); </pre><table style="margin: 10px 0px 0px; padding: 0px; border-style: solid; border-color: #aaaaaa; border-collapse: collapse; width: 709.0908813476563px;"><tbody style="margin: 0px; padding: 0px; border: 0px;"><tr style="margin: 0px; padding: 0px; border: 0px;"><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5; width: 262.7272644042969px;">方法</th><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5;">描述</th></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">open(<em style="margin: 0px; padding: 0px; border: 0px;">method</em>,<em style="margin: 0px; padding: 0px; border: 0px;">url</em>,<em style="margin: 0px; padding: 0px; border: 0px;">async</em>)</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;">规定请求的类型、URL 以及是否异步处理请求。</p><ul style="margin: 20px; padding: 0px; border: 0px; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">method</em>：请求的类型；GET 或 POST</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">url</em>：文件在服务器上的位置</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">async</em>：true（异步）或 false（同步）</li></ul></td></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">send(<em style="margin: 0px; padding: 0px; border: 0px;">string</em>)</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;">将请求发送到服务器。</p><ul style="margin: 20px; padding: 0px; border: 0px; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">string</em>：仅用于 POST 请求</li></ul></td></tr></tbody></table></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>GET 还是 POST？</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">与 POST 相比，GET 更简单也更快，并且在大部分情况下都能用。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">然而，在以下情况中，请使用 POST 请求：</p><ul style="margin: 10px 0px 0px 35px; padding: 0px; border: 0px;"><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">无法使用缓存文件（更新服务器上的文件或数据库）</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">向服务器发送大量数据（POST 没有数据量限制）</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">发送包含未知字符的用户输入时，POST 比 GET 更稳定也更可靠</li></ul></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>GET 请求</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">一个简单的 GET 请求：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","demo_get.asp",true); xmlhttp.send(); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_get" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">在上面的例子中，您可能得到的是缓存的结果。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">为了避免这种情况，请向 URL 添加一个唯一的 ID：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","demo_get.asp?t=" + <code style="margin: 0px; padding: 0px; border: 0px; font-family: 'Courier New', Courier, monospace; color: #0000dd;">Math.random()</code>,true); xmlhttp.send(); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_get_unique" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果您希望通过 GET 方法发送信息，请向 URL 添加信息：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","demo_get2.asp?fname=Bill&amp;lname=Gates",true); xmlhttp.send(); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_get2" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>POST 请求</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">一个简单 POST 请求：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("POST","demo_post.asp",true); xmlhttp.send(); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_post" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果需要像 HTML 表单那样 POST 数据，请使用 setRequestHeader() 来添加 HTTP 头。然后在 send() 方法中规定您希望发送的数据：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("POST","ajax_test.asp",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("fname=Bill&amp;lname=Gates"); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_post2" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><table style="margin: 10px 0px 0px; padding: 0px; border-style: solid; border-color: #aaaaaa; border-collapse: collapse; width: 709.0908813476563px;"><tbody style="margin: 0px; padding: 0px; border: 0px;"><tr style="margin: 0px; padding: 0px; border: 0px;"><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5; width: 262.7272644042969px;">方法</th><th style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid #aaaaaa; vertical-align: baseline; background-color: #d5d5d5;">描述</th></tr><tr style="margin: 0px; padding: 0px; border: 0px;"><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;">setRequestHeader(<em style="margin: 0px; padding: 0px; border: 0px;">header</em>,<em style="margin: 0px; padding: 0px; border: 0px;">value</em>)</td><td style="margin: 0px; padding: 5px 15px 5px 5px; border-style: solid; border-color: #aaaaaa; vertical-align: text-top; background-color: #efefef;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;">向请求添加 HTTP 头。</p><ul style="margin: 20px; padding: 0px; border: 0px; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">header</em>: 规定头的名称</li><li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc;"><em style="margin: 0px; padding: 0px; border: 0px;">value</em>: 规定头的值</li></ul></td></tr></tbody></table></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>url - 服务器上的文件</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">open() 方法的&nbsp;<em style="margin: 0px; padding: 0px; border: 0px;">url</em>&nbsp;参数是服务器上文件的地址：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","ajax_test.asp",true);</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">该文件可以是任何类型的文件，比如 .txt 和 .xml，或者服务器脚本文件，比如 .asp 和 .php （在传回响应之前，能够在服务器上执行任务）。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>异步 - True 或 False？</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">AJAX 指的是异步 JavaScript 和 XML（Asynchronous JavaScript and XML）。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">XMLHttpRequest 对象如果要用于 AJAX 的话，其 open() 方法的 async 参数必须设置为 true：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","ajax_test.asp",<code style="margin: 0px; padding: 0px; border: 0px; font-family: 'Courier New', Courier, monospace; color: #0000dd;">true</code>);</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">对于 web 开发人员来说，发送异步请求是一个巨大的进步。很多在服务器执行的任务都相当费时。AJAX 出现之前，这可能会引起应用程序挂起或停止。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">通过 AJAX，JavaScript 无需等待服务器的响应，而是：</p><ul style="margin: 10px 0px 0px 35px; padding: 0px; border: 0px;"><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">在等待服务器响应时执行其他脚本</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">当响应就绪后对响应进行处理</li></ul></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>Async = true</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">当使用 async=true 时，请规定在响应处于 onreadystatechange 事件中的就绪状态时执行的函数：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)     {     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;     }   } xmlhttp.open("GET","test1.txt",true); xmlhttp.send(); </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_async_true" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">您将在稍后的章节学习更多有关 onreadystatechange 的内容。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>Async = false</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如需使用 async=false，请将 open() 方法中的第三个参数改为 false：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","test1.txt",false);</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">我们不推荐使用 async=false，但是对于一些小型的请求，也是可以的。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请记住，JavaScript 会等到服务器响应就绪才继续执行。如果服务器繁忙或缓慢，应用程序会挂起或停止。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-weight: bold;">注释：</span>当您使用 async=false 时，请不要编写 onreadystatechange 函数 - 把代码放到 send() 语句后面即可：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">xmlhttp.open("GET","test1.txt",false); xmlhttp.send(); document.getElementById("myDiv").innerHTML=xmlhttp.responseText; </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;"><a href="http://www.w3school.com.cn/tiy/t.asp?f=ajax_async_false" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">亲自试一试</a></p></div><div id="bpn" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; height: 29px; width: 710px; background-color: #ffffff; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal;"><ul style="margin: 0px; padding: 0px; border: 0px; height: 29px; width: 230px; background-image: url(http://www.w3school.com.cn/ui/bg.gif); background-color: transparent; position: relative; background-position: 0px -570px; background-repeat: no-repeat no-repeat;"><li style="margin: 0px; padding: 0px; border: 0px; left: 0px; width: 105px; display: block; height: 29px; list-style: none; position: absolute; top: 0px; overflow: hidden;"></li></ul></div><img src ="http://www.blogjava.net/qileilove/aggbug/412739.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-21 14:09 <a href="http://www.blogjava.net/qileilove/articles/412739.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX - 创建 XMLHttpRequest 对象</title><link>http://www.blogjava.net/qileilove/articles/412738.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Apr 2014 06:07:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412738.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412738.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412738.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412738.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412738.html</trackback:ping><description><![CDATA[<div id="intro" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">XMLHttpRequest 是 AJAX 的基础。</span></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>XMLHttpRequest 对象</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">所有现代浏览器均支持 XMLHttpRequest 对象（IE5 和 IE6 使用 ActiveXObject）。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">XMLHttpRequest 用于在后台与服务器交换数据。这意味着可以在不重新加载整个网页的情况下，对网页的某部分进行更新。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>创建 XMLHttpRequest 对象</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">所有现代浏览器（IE7+、Firefox、Chrome、Safari 以及 Opera）均内建 XMLHttpRequest 对象。</p><h3>创建 XMLHttpRequest 对象的语法：</h3><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">variable=new XMLHttpRequest();</pre><h3>老版本的 Internet Explorer （IE5 和 IE6）使用 ActiveX 对象：</h3><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">variable=new ActiveXObject("Microsoft.XMLHTTP");</pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">为了应对所有的现代浏览器，包括 IE5 和 IE6，请检查浏览器是否支持 XMLHttpRequest 对象。如果支持，则创建 XMLHttpRequest 对象。如果不支持，则创建 ActiveXObject ：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">var xmlhttp; if (window.XMLHttpRequest)   {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE7+, Firefox, Chrome, Opera, Safari</span>   xmlhttp=new XMLHttpRequest();   } else   {<span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">// code for IE6, IE5</span>   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   } </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">在下一章中，您将学习发送服务器请求的知识。</p></div><img src ="http://www.blogjava.net/qileilove/aggbug/412738.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-21 14:07 <a href="http://www.blogjava.net/qileilove/articles/412738.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX 简介</title><link>http://www.blogjava.net/qileilove/articles/412731.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Apr 2014 05:24:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412731.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412731.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412731.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412731.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412731.html</trackback:ping><description><![CDATA[<div id="intro" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">AJAX 是一种在无需重新加载整个网页的情况下，能够更新部分网页的技术。</span></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>您应当具备的基础知识</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">在继续学习之前，您需要对下面的知识有基本的了解：</p><ul style="margin: 10px 0px 0px 35px; padding: 0px; border: 0px;"><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">HTML / XHTML</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">CSS</li><li style="margin: 3px 0px 0px; padding: 0px; border: 0px;">JavaScript / DOM</li></ul><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">如果您希望首先学习这些项目，请在我们的<a href="http://www.w3school.com.cn/index.html" title="W3School 在线教程" style="margin: 0px; padding: 0px; border: 0px; color: #900b09; background-color: transparent;">首页</a>访问这些教程。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>什么是 AJAX ？</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">AJAX = 异步 JavaScript 和 XML。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">AJAX 是一种用于创建快速动态网页的技术。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">通过在后台与服务器进行少量数据交换，AJAX 可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下，对网页的某部分进行更新。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">传统的网页（不使用 AJAX）如果需要更新内容，必需重载整个网页面。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">有很多使用 AJAX 的应用程序案例：新浪微博、Google 地图、开心网等等。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>Google Suggest</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">在 2005 年，Google 通过其 Google Suggest 使 AJAX 变得流行起来。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">Google Suggest 使用 AJAX 创造出动态性极强的 web 界面：当您在谷歌的搜索框输入关键字时，JavaScript 会把这些字符发送到服务器，然后服务器会返回一个搜索建议的列表。</p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>今天就开始使用 AJAX</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">AJAX 基于已有的标准。这些标准已被大多数开发者使用多年。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">请阅读下一章，看看 AJAX 是如何工作的！</p></div><div id="bpn" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; height: 29px; width: 710px; background-color: #ffffff; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal;"><ul style="margin: 0px; padding: 0px; border: 0px; height: 29px; width: 230px; background-image: url(http://www.w3school.com.cn/ui/bg.gif); background-color: transparent; position: relative; background-position: 0px -570px; background-repeat: no-repeat no-repeat;"><li style="margin: 0px; padding: 0px; border: 0px; left: 0px; width: 105px; display: block; height: 29px; list-style: none; position: absolute; top: 0px; overflow: hidden;"></li></ul></div><img src ="http://www.blogjava.net/qileilove/aggbug/412731.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-21 13:24 <a href="http://www.blogjava.net/qileilove/articles/412731.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX 实例</title><link>http://www.blogjava.net/qileilove/articles/412733.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Apr 2014 05:24:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412733.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412733.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412733.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412733.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412733.html</trackback:ping><description><![CDATA[<h1>AJAX 实例</h1><div id="tpn" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; height: 29px; width: 710px; background-color: #ffffff; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal;"><ul style="margin: 0px; padding: 0px; border: 0px; height: 29px; width: 230px; background-image: url(http://www.w3school.com.cn/ui/bg.gif); background-color: transparent; position: relative; background-position: 0px -570px; background-repeat: no-repeat no-repeat;"><li style="margin: 0px; padding: 0px; border: 0px; left: 0px; width: 105px; display: block; height: 29px; list-style: none; position: absolute; top: 0px; overflow: hidden;"><a href="http://www.w3school.com.cn/ajax/ajax_intro.asp" title="AJAX 简介" style="margin: 0px; padding: 0px; border: 0px; text-decoration: none; color: #900b09; background-color: transparent; display: block; height: 29px; text-indent: -9999px; background-position: initial initial; background-repeat: initial initial;">AJAX 简介</a></li><li style="margin: 0px; padding: 0px; border: 0px; left: 125px; width: 105px; display: block; height: 29px; list-style: none; position: absolute; top: 0px; overflow: hidden;"><a href="http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_create.asp" title="AJAX - 创建 XMLHttpRequest 对象" style="margin: 0px; padding: 0px; border: 0px; text-decoration: none; color: #900b09; background-color: transparent; display: block; height: 29px; text-indent: -9999px; background-position: initial initial; background-repeat: initial initial;">XHR 创建对象</a></li></ul></div><div id="intro" style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: 0px; font-family: 微软雅黑; font-size: 14px; font-weight: 800;">为了帮助您理解 AJAX 的工作原理，我们创建了一个小型的 AJAX 应用程序。</span></p></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>实例</h2><div id="myDiv" style="margin: 0px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-style: none; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px;"><p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px; color: #0479a7;">AJAX is not a programming language.</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px; color: #0479a7;">It is just a technique for creating better and more interactive web applications.</p></div><button type="button" style="margin: 15px 0px 0px; padding: 0px 5px; border: 1px solid #bebebe; height: 30px; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif;">通过 AJAX 改变内容</button></div><div style="margin: 0px 0px 0px 15px; padding-top: 20px; padding-bottom: 20px; border-width: 1px 0px; border-top-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-bottom-color: #aaaaaa; width: 710px; font-family: Verdana, Arial, 宋体; font-size: 11.818181991577148px; line-height: normal; background-color: #f9f9f9;"><h2>AJAX 实例解释</h2><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">上面的 AJAX 应用程序包含一个 div 和一个按钮。</p><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">div 部分用于显示来自服务器的信息。当按钮被点击时，它负责调用名为 loadXMLDoc() 的函数：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">&lt;html&gt; &lt;body&gt;  &lt;div id="myDiv"&gt;&lt;h3&gt;Let AJAX change this text&lt;/h3&gt;&lt;/div&gt; &lt;button type="button" <span style="margin: 0px; padding: 0px; border: 0px; color: #dd0000;">onclick="loadXMLDoc()"</span>&gt;Change Content&lt;/button&gt;  &lt;/body&gt; &lt;/html&gt; </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">接下来，在页面的 head 部分添加一个 &lt;script&gt; 标签。该标签中包含了这个 loadXMLDoc() 函数：</p><pre style="margin-top: 10px; margin-bottom: 0px; padding: 10px; border: 1px dotted #778855; font-family: 'Courier New', Courier, monospace; width: 685px; background-color: #f5f5f5;">&lt;head&gt; &lt;script type="text/javascript"&gt; function loadXMLDoc() { <span style="margin: 0px; padding: 0px; border: 0px; color: #999999;">.... AJAX script goes here ...</span> } &lt;/script&gt; &lt;/head&gt; </pre><p style="margin: 12px 0px 0px; padding: 0px; border: 0px; line-height: 18px;">下面的章节会为您讲解 AJAX 的工作原理。</p></div><img src ="http://www.blogjava.net/qileilove/aggbug/412733.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-21 13:24 <a href="http://www.blogjava.net/qileilove/articles/412733.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>