I have in frontend a javascript request and in backend a php that is using as url a php file. I want to know how can you redirect this? In one case I will initMap if table has data and another case I redirect.
PHP file api.php
$response = [
'status' => 'ok',
'data' => $database->resultset(),
];
if (empty($response['data'])) {
Flash::set_alert("Property details has successfuly saved. ");
$response=[
'status' => 'redirect',
'data' => '/search.php',
];
}
This is my response. An I don't know how in javascript to make a switch that handle the response, if the table is emtpy to redirect to search.php.
Javascript code
$(document).ready(function () {
$('#propertySearch').submit(function (e) {
e.preventDefault();
$.ajax({
url: 'api.php',
type: "POST",
dataType: 'json', // add json datatype to get json
data: $('#propertySearch').serialize(),
success: function (data) {
console.log(data);
initMap(data.data);
}
});
});
});