Ajax状态是“success”,但回调不能正常工作

时间:2015-08-16 23:28:56

标签: php jquery ajax pdo

我发送了$.post的Ajax请求。服务器端PHP是正确的。但回调和PHP无法正常工作!!

Ajax请求:

$("#exit").click(function(){
        swal({
             title: "exit",
             text: "Are you sure???",
             type: "info",
             animation: "slide-from-top",
             confirmButtonText:"Yes",
             cancelButtonText: "No",
             showCancelButton: true,
             closeOnConfirm: false,
             showLoaderOnConfirm: true,
            },
            function(){
                $.post("send.php",{method:'del',id:$("#hidden").val(),answerer:$("#hidden3").val()},function(data){
                alert(data);
        });
    });
});

和PHP:

 if($method==='del'){
        $qs_id=htmlentities($_POST['id']);
        $answerer=htmlentities($_POT['answerer']);
        include('config.php');
        $conn=new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8;",$username,$password);
        $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
        $DeleteQs=$conn->prepare("DELETE FROM qs WHERE id=:id");
        $DeleteQs->bindParam(':id',$qs_id);
        $DeleteQs->execute();
        $DeleteAnswer=$conn->prepare("DELETE FROM ans WHERE q_id=:id");
        $DeleteAnswer->bindParam(':id',$qs_id);
        $DeleteAnswer->execute();
        $ChangeStatus=$conn->prepare("UPDATE register SET wanted=0 WHERE name=:answerer");  
        $ChangeStatus->bindParam(':answerer',$answerer);        
        $ChangeStatus->execute();
        echo "Deleted";

    }

我想我应该说我已经获得了alert(),但它并未包含PHP消息。 我没有收到任何错误!

对不起,如果我的问题很愚蠢:(

1 个答案:

答案 0 :(得分:0)

这个问题可能发生在V1.8及更高版本的jQuery中,也许这种语法可以:

$.post("send.php",{method:'del',id:$("#hidden").val(),answerer:$("#hidden3").val()})
.done(function(response){
    alert(response)
})
.fail(function(response){
    alert("Failed:"+response);
})