I've recently picked up a project I was working on a bit ago, and when doing an ajax request, after it submits, it should return a success message or an error message. The code I'm using is the same code I'm using on the rest of my application, and it is working fine without any issues.
I've had the issue for the past 7 or so hours, and I have had no luck fixing it myself, hence why I'm coming here.
PHP Code:
if (access) {
$name = $_POST['name'];
dbquery('UPDATE settings SET name="' . escapestring($name) . '"');
$error['msg'] = "";
echo json_encode($error);
exit();
} else {
$error['msg'] = "You don't have permission.";
echo json_encode($error);
exit();
}
JS Code:
$(document).ready(function () {
$('#updateName').ajaxForm(function (error) {
error = JSON.parse(error);
if (error['msg'] === "") {
toastr.success('Name Updated', 'System:', {timeOut: 10000})
} else {
toastr.error(error['msg'], 'System:', {timeOut: 10000})
}
});
});
This code (the returning either success message or error message) seemingly works fine throughout the rest of my application, yet today I haven't been able to get it working no matter what I try.
Edit- After using console.log(error); , it appears it's not defined. The issue is that this code works fine on other parts of my application
log-
jQuery.Deferred exception: error is not defined ReferenceError: error is not defined