Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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 $.post数据html返回空值_Php_Ajax_Jquery - Fatal编程技术网

Php $.post数据html返回空值

Php $.post数据html返回空值,php,ajax,jquery,Php,Ajax,Jquery,当我使用$时,遇到了一些奇怪的问题。将发布到php文件。文件本身没有任何post回显“someresult”,当我转到$.post时,post数据的html()为空。。。帮帮我 $('#podborform').submit(function(){ var phone = $('#tour_selection_phone').val(); if(phone != null && phone != '' && phone.length >= 7

当我使用
$时,遇到了一些奇怪的问题。将
发布到php文件。文件本身没有任何post回显“someresult”,当我转到$.post时,post数据的html()为空。。。帮帮我

$('#podborform').submit(function(){
    var phone = $('#tour_selection_phone').val();
    if(phone != null && phone != '' && phone.length >= 7){
        var values = $(this).serialize();
        var qwer = String('captcha');
        var url = $(this).attr( 'action' );
        $.post( url, values,
            function( data ) {
                var content1 = $( data ).html();
                //content = String(content);
                //alert(qwer+'  -  '+content);
                if(content1 == qwer){
                    alert('Вы не правильно ввели код с картинки, попробуйте еще раз!');
                }
                if(content1 == 'false'){
                    alert('Извините произошла ошибка!');
                }
                if(content1 == 'true'){
                    alert('Ваша заявка успешно отправлена!');
                }
            }
        );
    }else{
        alert('Вы не ввели все обязательные поля!');
    }
    return false;
});
它连接到包含以下内容的php:

<?php
class mailer{
    //var $fields = array();
    function __construct(){
        if($this->captcha()){
            $this->sendmail();
        }else{
            exit('false');
        }
    }
    function sendmail(){
        foreach($_POST as $key=>$post){
            $text .= $key.': '.$post.PHP_EOL;
        }
        if(mail("123@gmail.com", "the subject", $text,
            "From: sales@123.ru\r\n"
           ."Reply-To: {$_POST['email']}\r\n"
           ."X-Mailer: PHP/" . phpversion())){
                exit('true');
            }else{
                exit('false_mail');
        }
    }
    function captcha(){
        require_once('recaptchalib.php');
        $privatekey = "123123";
        $resp = recaptcha_check_answer ($privatekey,
                                      $_SERVER["REMOTE_ADDR"],
                                      $_POST["recaptcha_challenge_field"],
                                      $_POST["recaptcha_response_field"]);

        if (!$resp->is_valid) {
          // What happens when the CAPTCHA was entered incorrectly
          echo 'captcha'; exit;
        } else {
            unset($_POST["recaptcha_challenge_field"],
                                      $_POST["recaptcha_response_field"]);
          return true;
        }
    }
}
    $mail = new mailer;
?>
您忘记了对象mailer构造上的()

$mail = new mailer;
应该是

$mail = new mailer();

.html
获取包含html的

范例

$('<div><img/></div>').html() // returns '<img/>'
$('test').html() // returns null

使用$mail=new-mailer时,它可以正常工作;我的意思是PHP文件返回结果。。。一直都是,但当我发布jquery时,没有显示结果这里的响应数据是什么?如果使用firebug,请检查控制台信息(数据)您希望从服务器获得什么类型的数据?字符串数据。。。我的意思是这个PHP文件他们不返回任何标签没有什么他们只返回'false'/'true'字符串。。。我想用字符串中的.html()获取它,然后做些什么。。。但是我得到null((请给出哪个PHP文件处理AJAX请求,或者至少是实际和预期的响应数据)。
if(data == qwer){
}
if(data == 'true'){
}