Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery ajax验证验证码_Php_Jquery_Ajax_Captcha - Fatal编程技术网

Php jQuery ajax验证验证码

Php jQuery ajax验证验证码,php,jquery,ajax,captcha,Php,Jquery,Ajax,Captcha,我在发布验证码以通过php验证时遇到问题。 我将captcha\u值字符串发送到captcha\u check.php,我不知道如何检索返回值'true'或'false' $("#myForm").submit(function() { $.ajax({ type: "POST", url: '/captcha_check.php', data: captcha_value success: function(data) {

我在发布验证码以通过php验证时遇到问题。 我将
captcha\u值
字符串发送到captcha\u check.php,我不知道如何检索返回值'true'或'false'

$("#myForm").submit(function() {
$.ajax({
       type: "POST",
       url: '/captcha_check.php',
       data: captcha_value
       success: function(data) {
          **?WHAT TO DO HERE? how to get true or false**
       }
});

captcha_check.php
<?php   

if ($_POST['captcha'] == $_SESSION['captcha'])
echo 'true';
else
echo 'false';
?>
$(“#myForm”).submit(函数(){
$.ajax({
类型:“POST”,
url:“/captcha_check.php”,
数据:验证码值
成功:功能(数据){
**?在这里做什么?如何判断真假**
}
});
captcha_check.php

我将标题设置为输出为xml

captcha_check.php

<?php   
header('Content-Type:text/xml');//needed to output as xml(that is my choice)
echo "<root><message>";
if ($_POST['captcha'] == $_SESSION['captcha'])
echo 'true';
else
echo 'false';
echo "</message></root>";
?>

$("#myForm").submit(function() {
$.ajax({
       type: "POST",
       url: '/captcha_check.php',
       dataType:'xml', 
       data: captcha_value
       success: function(data) {
          if($(data).find('message').text() == "true"){
             //now you get the true. do whatever you want. even call a function
            }
          else{
        //and false
          }
       }
});

$(“#myForm”).submit(函数(){
$.ajax({
类型:“POST”,
url:“/captcha_check.php”,
数据类型:'xml',
数据:验证码值
成功:功能(数据){
if($(数据).find('message').text()=“true”){
//现在你知道了。做你想做的任何事。甚至调用一个函数
}
否则{
//而且是假的
}
}
});

这是我的解决方案,可能也适用于您。我总是喜欢使用xml进行通信。这是我的选择。

我将标题设置为输出为xml

dataType: 'json', //Important:Sometimes JQuery fails to automatically detect it for you.
success: function(data) {
    console.log(data ? "Data is true" : "Data is false");
}
captcha_check.php

<?php   
header('Content-Type:text/xml');//needed to output as xml(that is my choice)
echo "<root><message>";
if ($_POST['captcha'] == $_SESSION['captcha'])
echo 'true';
else
echo 'false';
echo "</message></root>";
?>

$("#myForm").submit(function() {
$.ajax({
       type: "POST",
       url: '/captcha_check.php',
       dataType:'xml', 
       data: captcha_value
       success: function(data) {
          if($(data).find('message').text() == "true"){
             //now you get the true. do whatever you want. even call a function
            }
          else{
        //and false
          }
       }
});

$(“#myForm”).submit(函数(){
$.ajax({
类型:“POST”,
url:“/captcha_check.php”,
数据类型:'xml',
数据:验证码值
成功:功能(数据){
if($(数据).find('message').text()=“true”){
//现在你知道了。做你想做的任何事。甚至调用一个函数
}
否则{
//而且是假的
}
}
});
这是我的解决方案,可能也适用于您。我总是喜欢使用xml进行通信。这是我的选择。

在成功回调函数中给出“警报(数据)”来检查它。在成功回调函数中给出“警报(数据)”来检查它。
dataType: 'json', //Important:Sometimes JQuery fails to automatically detect it for you.
success: function(data) {
    console.log(data ? "Data is true" : "Data is false");
}