I am doing an ajax update. I just want a response of success or failure so I know how to handle some things in the front end. Problem is it isn't working. Brand new to all of this.
$('.delete-template-popup .confirm').on('click', function() {
var templateName = $('.loaded-template-name').html();
var templateArray = {};
templateArray.templateName = templateName;
var JSONObject = [templateArray];
var templateJson = JSON.stringify(JSONObject);
$.ajax({
url: 'http://localhost/ds-layouts/public/delete-template.php',
type: 'post',
data: {"templatePHP" : templateJson},
success: function(data) {
console.log(data)
if (data.status == "success") {
console.log(1)
}
// if (data.status == "success") {
// closePopup($('.delete-template-popup'));
// window.location.replace("http:////localhost/ds-layouts/public/manage-layouts.php");
// } else {
// $('.delete-template-popup .error').show().html('An error occurred processing your request. Please try again. If this error persists contact blah.');
// }
}
});
});
and the php
if ($flag) {
//mysqli_commit($connection);
if ($debug) {
echo "pass";
echo "
";
}
//$_SESSION["message"] = "Template delete was successful.";
//header('Content-Type: application/json');
header('Content-Type: application/json; charset=UTF8');
echo json_encode(array('status' => 'success'));
} else {
if ($debug) {
echo "fail";
echo "
";
}
//mysqli_rollback($connection);
// header('Content-Type: application/json');
// echo json_encode(array('status' => 'failure'));
}
So the deal is I am getting into the if block of the php statment fine. If I have the header part of the block I get all of my echo statements passed properly and I can read them in Chromes developer console. The moment I uncomment the header statement nothing works. This is for either one of $flag cases true or false.
I have this same type of script in another area and it works absolutely fine. Don't mind the comments. I was just commenting things out as a way to figure out where things were breaking. That is how I determened the header was causing it.