Adamlin0708 Adamlin0708 - 3 years ago 157
PHP Question

why can't I call php file with ajax in Cpanel?

I'm trying to call php file with ajax, but it seems there's a bug to fix, but I can't find it.....

here's my button in html (p.s $row["id"] is a variable represented article id)

<button type='button' class='btn btn-danger delete' data-info-id='<?php echo $row["id"];?>'>Delete</button>

and here's my ajax code

$(document).on('click', '.delete', function() {
var info_id = $(this).data("info-id");
var deleteUrl = "/delete.php";
type: "POST",
url: deleteUrl,
data: { 'info-id': info_id },
dataType: 'json',
success: function (results) {

And here's delete.php, just test if it receives the variables from ajax or not


$id = $_POST['info-id'];

$result = json_encode($id);

return $result;


But I there's nothing showed in console.log

Hope someone can give me some advises to fix this!


Answer Source


return $result;


echo $result;

return is for returning, echo is for echoing (printing).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download