jquery ajax返回true但未显示正确的消息?

jquery ajax返回true但未显示正确的消息?,jquery,Jquery,我有以下代码 $(document).ready(function(){ // class exists if($('.delete').length) { // add click handler $('.delete').click(function(){ // ask for confirmation var result = confirm('Are you sure you want to delete this?');

我有以下代码

$(document).ready(function(){
// class exists
if($('.delete').length) {
        // add click handler
    $('.delete').click(function(){
        // ask for confirmation
        var result = confirm('Are you sure you want to delete this?');
        var vid     = $(this).attr('id'); 
        var row = $(this).parents('tr');  
        // do ajax request
        if(result) {
            $.ajax({
                type:"POST",
                url:"delete_joke.php",
                data:{id:vid,garbage:'FG9g543hfh'},
                dataType: "json",
                success:function(response){

                    // hide table row on success
                    if(response == "true") {
                        row.fadeOut();
                       $('#errors').show();
                        $('#errors').html( '<div class="message green"> Successfully deleted!<img src="http://puppetweb.ca/play/views/admin/gfx/icon-close.gif" alt="Close this item" /> </div>' ).show();

                    }else{
                       $('#errors').show();
                        $('#errors').html( '<div class="message red"> Error deleting. <img src="http://puppetweb.ca/play/views/admin/gfx/icon-close.gif" alt="Close this item" /> </div>' ).show();

                    }
                }
            });
        }
    return false;
    });
}
});
它一直工作到我想要显示成功的部分,我让php脚本在成功时打印true,在错误时打印false,如果我执行alertresponse,它会显示单词true。但它显示的是成功时删除错误和错误时删除错误

有什么帮助吗?

如果确定ifresponse返回true/false,请尝试将ifresponse==true替换为ifresponse

要检查数据响应的类型,请尝试alerttypeof response并查看它显示的内容

编辑:

因为您提到的数据类型是JSON,所以请确保返回有效的响应,并在响应中将内容类型设置为JSON


如果json返回值为{status:true},那么应该使用ifresponse.status

这里的问题是作用域。当success函数运行时,行不等于任何值。其中一个最简单的解决方案是传回id,对其进行精确设置,将其用作选择器,然后隐藏


如果我这样做,我会从json切换到scrip并返回JavaScript来执行。这似乎比正确或错误更有用。

请同时发布php代码。也许问题就在那里。