Home > Web Front-end > JS Tutorial > body text

jQuery+Ajax determines whether the entered verification code passes

php中世界最好的语言
Release: 2018-04-02 09:21:32
Original
1957 people have browsed it

This time I will bring you jQuery+Ajax to determine whether the input verification code passes. What are the precautions for jQuery+Ajax to determine whether the input verification code passes. The following is a practical case, let's take a look.

Without further ado, I will post the code directly for you. The specific code is as follows:

<script src="js/j.js"></script>
<script>
$(document).ready(function(e) {
 $('#yes').hide();
 $('#no').hide();
  $('input[name=gcode]').keyup(function(){
   if($(this).val().length==4){
  $.post('gbook.php',{cc:$('input[name=gcode]').val()},function(msg){
   
   if(msg=='yes'){
    $('#no').hide();
    $('#yes').show();
   }else{
    $('#yes').hide();
    $("#no").show();
   }
  });
  }
 });
});
</script>
Copy after login

First introduce the html code of jquery

.sl-error-verifycode {
 background-image: url("images/icons.png");
 background-position: -26px 0;
 background-repeat: no-repeat;
 display: block;
 font-size: 18px;
 height: 23px;
 line-height: 20px;
 margin-left: 180px;
 margin-top: -25px;
 position: relative;
 text-align: center;
 width: 20px;
 z-index: 2;
}
.sl-correct-verifycode {
 background-image: url("images/icons.png");
 background-position: -50px 0;
 background-repeat: no-repeat;
 display: block;
 font-size: 18px;
 height: 23px;
 line-height: 20px;
 margin-left: 180px;
 margin-top: -25px;
 position: relative;
 text-align: center;
 width: 20px;
 z-index: 2;
}
Copy after login

verification code

<tr>
  <td height="40" align="right">验证码:</td>
  <td height="40"><span class="addred">*</span></td>
  <td height="40">
  <input type="text" name="gcode" id="textfield7" class="txtlist">
<span id="yes" class="sl-correct-verifycode"></span><span id="no" class="sl-error-verifycode"></span>
  <img style="float:right; margin-top:-25px; margin-right:300px;" align="middle" src="inc/cc.php" onClick="this.src=&#39;inc/cc.php?&#39;+new Date" title="点击换一张图片" width="100px"></td>
 </tr>
Copy after login

gbook.php

<?php
session_start();
if(isset($_POST['cc'])){
 $cc = strtolower($_POST['cc']);
 $ss = strtolower($_SESSION['code']);
 if($cc==$ss){
   echo "yes";
 }else{
   echo "no"; 
 }
}
Copy after login

Note that pictures must be imported

I believe you have mastered the method after reading the case in this article. Please pay attention for more exciting things. Other related articles on php Chinese website!

Recommended reading:

How to implement real-time editing of tables with PHP+Ajax

Use ajax to implement session timeout jump log in page

The above is the detailed content of jQuery+Ajax determines whether the entered verification code passes. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!