检查是否加载了php文件

时间:2012-09-02 20:50:10

标签: php jquery ajax

我有一个简单的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);
> 
> ?>

如果它在同一个文件夹中,我应该给出什么网址?只有它的名字在上面? 那会有用吗? (在delete.php中)

  

回波( “警报( 'OK');”);

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

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

首先,要检查失败,请使用:

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

我个人喜欢返回一个JSON字符串,其中包含操作是否成功以及是否发生了错误 - 这可以让您区分HTTP问题(.success().error()寻找),并判断你是否应该继续或死亡。

相关问题