如何将captcha-ajax php和验证结合使用?当我提交表单时,它不能刷新


how to use captcha ajax php and validation together? When i submit the form it must not refresh

我从表单标签开始,添加名称年龄电话号码简历输入框和captcha,但无法通过ajax将表单发送到将发送邮件的php文件。当我发送邮件时,屏幕会刷新**

 <form action="#" name="MYFORM" id="MYFORM">
          <label>Name</label>
**then i put other labels**
          <input name="name" size="30" type="text" id="name">
          <br clear="all" />
          <label>Email</label>
          <input name="email" size="30" type="text" id="email">
          <br clear="all" />
          <div id="wrap" align="center">
            <img src="get_captcha.php" alt="" id="captcha" />
            <br clear="all" />
            <input name="code" type="text" id="code">
          </div>
          <img src="refresh.jpg" width="25" alt="" id="refresh" />
          <label>&nbsp;</label>
          <input value="Send" type="submit" id="Send">
        </form>

您可以在文件get_captcha.php中使用SESSION来存储captcha代码的值,当您提交代码时,用户输入的captcha码的post值与SESSION中保存的值相匹配。

假设您正在寻找ajax表单提交

 $.ajax({  
  type:'POST', 
  url: 'yourphpfile.php', 
  data:$('#formid').serialize(), 
  success: function(response) 
  {
     // do what ever you want with the repose 
  }
});

在php文件中,通过比较会话中生成和存储的captcha值来指定captcha的验证。如果captcha无法根据您获得的响应使用javascript显示错误