<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post/1484/</link>
<title><![CDATA[ajax的基础实例，用于从数据库中检测动态检测用户名是否已经存在]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 10 Dec 2008 10:34:37 +0000</pubDate> 
<guid>http://www.jackxiang.com/post/1484/</guid> 
<description>
<![CDATA[ 
	ajax的基础实例，用于从数据库中检测动态检测用户名是否已经存在（php+mysql，其他只要在test.php程序上改成相应的语言就可以了！）<br/>test.html<br/><div class="code">&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html;charset=utf-8&quot; /&gt;<br/>&lt;/head&gt;<br/>&lt;script language=&quot;javascript&quot;&gt;<br/>&lt;!--<br/>function AjaxLib()<br/>&#123;<br/>//创建AJAX实例<br/>try &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; xmlhttp = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch (e) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; try &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp; &#125; catch (err) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp = null;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(!xmlhttp &amp;&amp; typeof XMLHttpRequest != &quot;undefined&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp; xmlhttp = new XMLHttpRequest();<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (!xmlhttp)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; return null; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return xmlhttp; <br/>&#125;<br/>function AjaxCheck(obj)<br/>&#123;<br/>//判断检测用户名<br/>var xmlObj&nbsp;&nbsp;= AjaxLib();<br/>var objId&nbsp;&nbsp;= obj.id;<br/>var userName = document.getElementById(objId);<br/>var url&nbsp;&nbsp; = &quot;test.php?userName=&quot; + userName.value;<br/>xmlObj.onreadystatechange = function ()<br/>&#123;<br/>&nbsp;&nbsp;if (xmlObj.readyState == 4)<br/>&nbsp;&nbsp;&#123;&nbsp;&nbsp; <br/>&nbsp;&nbsp; var objHelpId = document.getElementById(&quot;userNameHelp&quot;);<br/>&nbsp;&nbsp; if (xmlObj.responseText == &quot;ok&quot;)<br/>&nbsp;&nbsp; &#123;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;objHelpId.innerHTML = &quot;可以使用&quot;;<br/>&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp; else<br/>&nbsp;&nbsp; &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;objHelpId.innerHTML = &quot;已经有此用户，请更换一个用户名！&quot;;<br/>&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>xmlObj.open(&quot;GET&quot;, url, true);<br/>xmlObj.send(null);<br/>&#125;<br/>--&gt;<br/>&lt;/script&gt;<br/>&lt;body&gt;<br/>&lt;form action=&quot;&quot; name=&quot;f&quot; id=&quot;f&quot;&gt;<br/>&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; width=&quot;400&quot; cellpadding=&quot;0&quot;&gt;<br/>&nbsp;&nbsp;&lt;tr&gt;&lt;td&gt;<br/>&nbsp;&nbsp; &lt;div&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style=&quot;float:left&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; user &lt;input type=&quot;text&quot; name=&quot;userName&quot; onchange=&quot;AjaxCheck(this)&quot; id=&quot;userName&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;userNameHelp&quot; style=&quot;color:red; float:right&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br/>&nbsp;&nbsp; &lt;/div&gt;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&lt;/td&gt;&lt;/tr&gt;<br/>&nbsp;&nbsp;&lt;tr&gt;&lt;td&gt;password &lt;input type=&quot;text&quot; name=&quot;userPassword&quot; id=&quot;userPassword&quot;&gt;&lt;/td&gt;&lt;/tr&gt;<br/>&lt;/table&gt;<br/>&lt;/form&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;</div><br/><br/>test.php<br/><br/><div class="code"><br/>&lt;?php<br/>/**<br/>* ajax判断异步判断用户名<br/>*<br/>* 数据库：user; 表：user;<br/>*<br/>*/<br/>//header(&quot;Content-Type: text/html; charset=UTF-8&#92;n&quot;);<br/>//echo &quot;&lt;meta http-equiv=&#039;content-type&#039; content=&#039;text/html;charset=utf-8&#039;&gt;&quot;;<br/>$link = mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;);&nbsp;&nbsp;//连接数据库<br/>mysql_select_db(&quot;user&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //打开数据库<br/>mysql_query(&quot;set names &#039;utf8&#039;&quot;);&nbsp;&nbsp;&nbsp;&nbsp; //设置字符集<br/>$userName = isset($_GET&#91;&quot;userName&quot;&#93;) ? $_GET&#91;&quot;userName&quot;&#93; : &quot;&quot;; //取得URL后要检测的用户名<br/>//$userName = &quot;袁相宜&quot;;<br/>$userName = iconv(&quot;GB2312&quot;, &quot;UTF-8&quot;, $userName); //把接收的值转换成utf8码<br/>if (empty($userName))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//判断是否是空值<br/>&#123;<br/>echo &quot;fail&quot;<br/>exit();<br/>&#125;<br/>$sql = &quot;SELECT * FROM user WHERE userName = &#039;&#123;$userName&#125;&#039;&quot;;<br/>$result = mysql_query($sql, $link);<br/>if (mysql_num_rows($result) &gt; 0)<br/>&#123;<br/>$tip = &quot;fail&quot;;<br/>&#125;<br/>else<br/>&#123;<br/>$tip = &quot;ok&quot;;<br/>&#125;<br/>echo($tip);<br/>exit(0);<br/>?&gt;</div><br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post/1484/#blogcomment51630</link>
<title><![CDATA[[评论] ajax的基础实例，用于从数据库中检测动态检测用户名是否已经存在]]></title> 
<author>123 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 17 Aug 2010 07:44:23 +0000</pubDate> 
<guid>http://www.jackxiang.com/post/1484/#blogcomment51630</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>