检查php文件是否已加载


Check if php file is loaded

我得到了一个简单的jquery函数,它应该从数据库中删除一行,我的脚本是:

//

// delete the entry once we have confirmed that it should be deleted
$('.delete').click(function() {
    var parent = $(this).closest('tr');

    $.ajax({
        type: 'get',
        url: 'delete.php', // <- replace this with your url here
        data: 'ajax=1&delete=' + $(this).attr('id'),
        beforeSend: function() {
            parent.animate({'backgroundColor':'#fb6c6c'},300);
        },
        success: function() {
            parent.fadeOut(300,function() {
                parent.remove();
            });
        }
    });        
});
// confirm that it should be deleted
$('.delete').confirm({
    msg:'Do you really want to delete this?',
    timeout:3000
});     }); // ]]></script>

当我点击bitton-dalete行(在屏幕上),但在数据库中它仍然存在,如何检查php是否被执行?我的php文件:

> <?php     $con = mysql_connect("localhost","root",""); if (!$con)   {  
> die('Could not connect: ' . mysql_error());   }
> 
> mysql_select_db("xxx", $con);
> $sql="DELETE FROM
> `submission_values` WHERE  SubmissionId =49";   
> mysql_query($sql,$con);
> 
> ?>

如果它在同一个文件夹中,我应该给出什么url?只有像上面这样的名字?这样行吗?(在delete.php中)

echo("alert('ok');");

在php文件中,您可以回显响应。然后使用jQuery的response对象,您可以检查响应的值,看看php脚本是否运行到了该回显行。

您需要在失败时触发一些错误条件。

首先,要检查故障,请使用以下内容:

if( $e = mysql_error()) {/* report $e */}

就我个人而言,我喜欢返回一个JSON字符串,其中包含操作是否成功,如果不成功,发生了什么错误——这允许您区分HTTP问题(这是.success().error()所寻找的),并判断您是应该继续还是应该终止。