Rumah > php教程 > php手册 > teks badan

ajax验证用户名和密码,ajax验证用户名

WBOY
Lepaskan: 2016-06-13 09:29:26
asal
1369 orang telah melayarinya

ajax验证用户名和密码,ajax验证用户名

<span><span> 1</span>     <span>var</span> user = form.name.<span>value;
</span><span> 2</span>     <span>var</span> password = form.password.<span>value;
</span><span> 3</span>     <span>var</span> url = "chkname.php?user="+user+"&password="+password;<span>//</span><span>以前只知道ajax用于对用户名的检测,原来还可以对密码进行检测。</span>
<span> 4</span>     xmlhttp.open("GET",url,<span>true</span><span>);
</span><span> 5</span>     xmlhttp.onreadystatechange = <span>function</span><span>(){
</span><span> 6</span>     <span>if</span>(xmlhttp.readyState == 4<span>){
</span><span> 7</span>             <span>var</span> msg = xmlhttp.<span>responseText;
</span><span> 8</span>             <span>if</span>(msg == '1'<span>){
</span><span> 9</span>                 alert('用户名或密码错误!!'<span>);
</span><span>10</span>                 form.password.<span>select();
</span><span>11</span>                 form.check.value = ''<span>;
</span><span>12</span> <span>                code(form);
</span><span>13</span>                 <span>return</span> <span>false</span><span>;
</span><span>14</span>             }<span>if</span>(msg == "3"<span>){
</span><span>15</span>                 alert("用户名被占用,请重新输入!"<span>);
</span><span>16</span>                 <span>return</span> <span>false</span><span>;
</span><span>17</span>             }<span>else</span><span>{
</span><span>18</span>                 alert('欢迎光临'<span>);
</span><span>19</span>                 location.<span>reload();
</span><span>20</span> <span>            }
</span><span>21</span> <span>        }
</span><span>22</span> <span>    }
</span><span>23</span>     xmlhttp.send(<span>null</span><span>);
</span><span>24</span>     <span>return</span> <span>false</span>;</span>
Salin selepas log masuk

php通过ajax实现用户名与数据库中用户验证

第一步需要一个 jq的js文件
#47;/W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">



Login<br><script type="text/javascript" src="<?php%20echo%20%24this->baseUrl%20?>/public/js/jq1.7.js"></script><br /><script language="javascript"><br />$(document).ready(function(){<br />$("#submit").click(function(){<br />if( $("#uname").val() == "" || $("#upas").val() == "" ){<br />alert("用户名或者密码不能为空");<br />return false;<br />}else{<br />$("#showerrormessage").load(<br />'<?php echo $this->baseUrl ?>/index/login',<br />{uname:$("#uname").val(),upas:$("#upas").val()},<br />function(data){<br />if(data == 1){<br />$("#showerrormessage").html('login success!!!');<br />}else{<br />$("#showerrormessage").html('login error~~~');<br />}<br />}<br />);<br />}<br />});<br />});<br /></script><br /></head><br /><body><br /><form id="form1" name="form1" method="post" action=""><br />用户名:<input type="te......余下全文>><br/>   <p class="header2"><span class="icon i-relatedanswer"><h3>我想用jsp+ajax技术实现登录的用户名与密码验证,主要是用javascript来做<p class="best-replyer"> <p class="ft p1">Ajax我会.但JSP我只是个半吊子<br/>   </script>
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan