I want to send POST request with jquery AJAX to PHP function but it don't give any respond.
JQuery
$.ajax({
url: 'ListProduk.php/SelectData',
type: 'POST',
success: function(data)
{
console.log(data);
}
});
PHP
<?php
include 'database.php';
function SelectData(){
$sql = "SELECT * FROM MsProduk";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$arr[] = $row;
}
return json_encode($arr);
}
?>
Any ideas how to fix it?
url: 'ListProduk.php/SelectData',that doesn't make sense. Look at your developer console, use php's error reporting and check for errors on the query. You'll see what's (not) happening here.url: 'ListProduk.php/SelectData',that translates to having a folder calledListProduk.phpwith a sub-folder calledSelectData. TheSelectData()method's usage is unknown. You've a variable scope issue here.GETvariable and just call it from within your php file.