<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yaron's Blog &#187; AJAX编程</title>
	<atom:link href="http://yaron.org.cn/archives/category/web-developement/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://yaron.org.cn</link>
	<description>About PHP MYSQL JS WEB FreeBSD etc.</description>
	<lastBuildDate>Sat, 31 Jul 2010 13:54:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AJAX编程基础笔记</title>
		<link>http://yaron.org.cn/archives/107</link>
		<comments>http://yaron.org.cn/archives/107#comments</comments>
		<pubDate>Sun, 22 Mar 2009 07:40:38 +0000</pubDate>
		<dc:creator>Yaron</dc:creator>
				<category><![CDATA[AJAX编程]]></category>

		<guid isPermaLink="false">http://yaron.org.cn/archives/107</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160; AJAX异步传输，原理是利用JS的XMLHttpRequest对象，直接和服务器通信，局部重载。在WEB设计中，交互性更强！
 
1&#160; 创建XMLHttpRequest对象
&#160;&#160;&#160; 由于不同浏览器，XMLHttpRequest对象的创建方式不同，所以浏览器判断或者创建成功与否的判断，就十分必要！
2&#160; 使用XMLHttpRequest对象创建异步HTTP请求
2.1&#160; onreadystatechange属性服务器响应的函数；
2.2&#160; readystate属性存有服务器响应的状态信息，每当它改变时，onreadystatechange函数就回执行；
2.3&#160; responseText属性，用于取回服务器返回的数据。
2.4&#160; open()方法功能在服务器端执行脚本，send()方法向服务器发送请求
3&#160; 实例
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
&#60; !DOCTYPE html PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34; &#34;http://www.w3.org/TR/html4/loose.dtd&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34;<a href="http://yaron.org.cn/archives/107" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>&#160;&#160;&#160;&#160;&#160; AJAX异步传输，原理是利用JS的XMLHttpRequest对象，直接和服务器通信，局部重载。在WEB设计中，交互性更强！</p>
<p> <span id="more-107"></span><br />
<h5>1&#160; 创建XMLHttpRequest对象</h5>
<p>&#160;&#160;&#160; 由于不同浏览器，XMLHttpRequest对象的创建方式不同，所以浏览器判断或者创建成功与否的判断，就十分必要！</p>
<h5>2&#160; 使用XMLHttpRequest对象创建异步HTTP请求</h5>
<p>2.1&#160; onreadystatechange属性服务器响应的函数；</p>
<p>2.2&#160; readystate属性存有服务器响应的状态信息，每当它改变时，onreadystatechange函数就回执行；</p>
<p>2.3&#160; responseText属性，用于取回服务器返回的数据。</p>
<p>2.4&#160; open()方法功能在服务器端执行脚本，send()方法向服务器发送请求</p>
<h5>3&#160; 实例</h5>
<p>index.html</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=GB18030&quot; /&gt;
&lt;title&gt;AJAX Test&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; &gt;
function ajaxFunction(){
  var xmlHttp;
  try{
    xmlHttp=new XMLHttpRequest();
  } 
  catch(e) {
    try{
      xmlHttp=new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
    } 
    catch(e) {
      try{
	xmlHttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
      } 
      catch(e) {
	alert(&quot;Your Browser does not support AJAX!&quot;);
	return false;
      }
    }
  }
&nbsp;
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      document.getElementById(&quot;time&quot;).value = xmlHttp.responseText;
      //document.myForm.time.value=xmlHttp.responseText;
    }
  }
  xmlHttp.open(&quot;GET&quot;,&quot;ajax.php&quot;,true);
  xmlHttp.send(null);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
&lt;form name=&quot;myForm&quot;&gt;
UserName: &lt;input type=&quot;text&quot; name=&quot;userName&quot; onKeyup=&quot;ajaxFunction()&quot; /&gt;
Time: &lt;input type=&quot;text&quot; name=&quot;time&quot; id=&quot;time&quot;/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>使用 XMLHttp=new XMLHttpRequest() 来创建此对象。这条语句针对 Firefox、Opera 以及 Safari 浏览器。假如失败，则尝试针对 Internet Explorer 6.0+ 的 xmlHttp=new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;)，假如也不成功，则尝试针对 Internet Explorer 5.5+ 的 xmlHttp=new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;)。</p>
<p>
ajax.php
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://yaron.org.cn/archives/107/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
