duanpanhuo0618 2015-01-03 14:00
浏览 34

php captcha使用jquery ajax

i have included a captcha functionality to my wordpress site using this plugin: https://github.com/claviska/simple-php-captcha

however i am having difficulities validating the form data and captcha using ajax.

i using .submit() to make an ajax post request which sends all the form data to a php file.

however the problem i am facing is that the captcha code keeps changing and therefore my validation will always result to invalid.

this code is placed at the top of single.php:

session_start();
require_once('library/includes/plugins/simple_php_captcha/index.php');
$_SESSION['captcha'] = simple_php_captcha();

this code is placed further down single.php:

<img src="<?php echo $_SESSION['captcha']['image_src'];?>" alt="captcha"/>

this code is placed in ajax-submit.php

session_start();
if($_POST){
    echo "<pre>";
    echo print_r($_POST);
    echo "</pre>";
    echo $_SESSION['captcha']['code'];
}

this is the .submit()

$("form").submit(function () {

   var input_captcha = $("#input_captcha").val();

        $.ajax({
            url: 'ajax-submit.php',
            type: "POST",
            data: "input_captcha="+input_captcha,
            //dataType: "json",
            cache: false,
            success: function(data) {

            }
        });

        return false;

    });

where am i doing/going wrong??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效