检查删除是否成功消息php ajax jquery mysql

时间:2011-12-23 00:00:32

标签: php jquery mysql ajax

嗨大家甚至我已成功删除消息返回虚假删除消息(“无法删除”)除了成功删除消息但查询是wokrking 请告诉我我错在哪里这是我的代码\

delete.php

  if(isset($_POST['delete_id']) && !empty($_POST['delete_id'])) {
          $delete_id = mysql_real_escape_string($_POST['delete_id']);
    $query=mysql_query("DELETE FROM color WHERE idColor='$delete_id'");
    if($query != false) {
            echo 'true';
          }
    mysql_close();
<script>
 $(document).ready(function(){
        $('.del_btn').click(function(){
        if (confirm("Are you sure you want to delete this Color?"))
       var del_id = $(this).attr('rel');
              $.post('script/delete_color.php', {delete_id:del_id}, function(data) {
          if(data == 'true') {
            $('#'+del_id).remove();alert('Color has been deleted!');
          }
           else {
            alert('Color could not delete!');
          }
                document.messages.submit();
            return false; // This line added}
    });
    }); 
    });

</script>

1 个答案:

答案 0 :(得分:0)

我真的不明白你的问题,但我会采取有根据的猜测...

您需要将逻辑包装在“confirm”IF语句中。另外,你有一个额外的“});”。

$(document).ready(function(){

    $('.del_btn').click(function() {

        if (confirm("Are you sure you want to delete this Color?")) {

            var del_id = $(this).attr('rel');

            $.post('script/delete_color.php', {delete_id:del_id}, function(data) {

                if(data == 'true') {
                    $('#'+del_id).remove();alert('Color has been deleted!');
                } else {
                    alert('Color could not delete!');
                }

                document.messages.submit();
                return false; // This line added
            }
        }
    });
});