jQuery.ajax post is being sent but $_POST is empty

1k views Asked by At

I am trying to send information using AJAX from JavaScript in one file to PHP in another file. When I inspect the page on chrome after I have pressed the button, it shows the values under the form data sub section in networks, however, if I var_dump[$_POST] it shows it is empty.

Here is my JavaScript:

function details(id) {
    var data = {"id" : id};

    jQuery.ajax({
        url: "/Example/includes/detail.php",
        type: 'POST',
        data: data,
        success: function(data){
            jQuery('body').append(data);
        },
        error: function(){
            alert("Error");
        }
    }); 
}

Here is the PHP:

<?php
$id = $_POST['id'];
$id = (int)$id;
?>

Any help would be greatly appreciated. Thanks

0

There are 0 answers