Using ajax to execute a code in php

0

Hello, I have a problem with how to use ajax to run a code in php, I'm trying to find the problem for hours, but I can not.

js code

$.ajax({                        
    url: 'deletarOrgs.php',
    data: {
       id: $id
    },
    type: 'POST',
    success: function(){
        alert("sucess");
    },
    error: function(){
        alert("error");
    }
});

php code

<?php 
    include 'class/OrgaosColabDAO.php';    
    $DAO = new OrgaosColabDAO();
    $DAO->deletarOC($_POST['id']);    
?>

I tested php separately, it works fine. When I run js, ajax performs the error function.

Thanks in advance.

Edit:

The purpose of ajax is to delete an object from my bank, to control when I want to delete it, I click on a button that opens a modal (I'm using modal bootstrap 3) where it has 2 buttons, yes or no . Ajax executes when I click the Yes button. The strange thing is when I do not use the modal, running ajax when I click the first button, ajax works the right way.

$('#deletar-sim').click(function (){                    
    $.ajax({                        
        url: 'deletarOrgs.php',
            data: {
                id: $id
            },
            type: 'POST',
            success: function(){
                alert("a");
            },
            error: function (request, status, error){
                alert(request.responseText);
            }
    });
});
    
asked by anonymous 30.06.2016 / 03:55

0 answers