|
|
建立一個ajax.js文件,代碼如下: // JavaScript Document var xmlHttp; function S_xmlhttprequest() { xmlHttp=null; if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. xmlHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6, IE5 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } function getName(name) { if(name = document.myform.name.value) { S_xmlhttprequest(); xmlHttp.open("get","date.php?name="+name,true); xmlHttp.onreadystatechange = byname; xmlHttp.send(null); } } function byname() { if(xmlHttp.readyState ==1) { document.getElementById('name').innerHTML = "<font color=red>loading....</font>"; } if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { var name = xmlHttp.responseText; document.getElementById('name').innerHTML = name; } } } function getEmail(email) { var email = document.myform.email.value; if(email =="") { alert("用戶名不能為空"); document.myform.email.focus(); return false; } else { S_xmlhttprequest(); xmlHttp.open("get","date.php?email="+email,true); xmlHttp.onreadystatechange = byemail; xmlHttp.send(null); } } function byemail() { if(xmlHttp.readyState ==1) { document.getElementById('email').innerHTML = "<font color=red>loading....</font>"; } if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { var email = xmlHttp.responseText; document.getElementById('email').innerHTML = email; } } } 建立一個register.php文件,代碼如下: <title>註冊頁面</title> <script src="Ajax.js" language="javascript"> </script> <body> <form action="" method="post" name="myform"> <table align="center"> <tr><td>用戶名:</td><td><input type="text" name="name" value="" onblur="getName('name')"/></td><td><div id="name"><font color="#CC66CC">*用戶名必填*</font></div></td></tr> <tr><td>郵箱:</td><td><input type="text" name="email" value="" onblur="getEmail('email')"/></td><td><div id="email"><font color="#CC66CC">*郵箱必填*</font></div></td></tr> </table> </form> 建立一個date.php頁面,用於查詢數據庫 : <? sleep(1); $connt = mysql_connect("localhost","root","123456"); mysql_select_db('test',$connt ); mysql_query("set names 'gb2312'"); if($_GET['name']) { $name = $_GET['name']; $sql = "select * from test where name='$name'"; $restul = mysql_query($sql); $array = mysql_fetch_row($restul); // print_r($array); if(is_array($array)) { echo "<font color='red'>該用戶名已經存在</font>"; } else { echo "<font color='red'>該用戶名可以用</font>"; } } if($_GET['email']) { $name = $_GET['email']; $sql = "select * from test where email='$email'"; $restul = mysql_query($sql); $array = mysql_fetch_row($restul); // print_r($array); if(is_array($array)) { echo "<font color='red'>該郵箱已存在</font>"; } else { echo "<font color='red'>該郵箱可以用</font>"; } } ?> 這樣就可以實現註冊的時候局部刷新的效果 ecshop模板 网站模板 |
提醒您:
您在"ECSHOP 交流討論區"交流請遵守台灣法律規範,"最模板"
發表的文章《ecshop模板中如何實現局部刷新》版權歸屬作者所有,如是轉貼版權歸屬原作者所有.本論壇不對其真實性做任何考證.