gsr
11/02/2023, 6:51 PMrodel30
11/02/2023, 6:59 PMonsubmit
on the form tag, which is calling your funciton, and then you're also attaching an event handlerRyan Albrecht
11/02/2023, 6:59 PMRyan Albrecht
11/02/2023, 6:59 PMgsr
11/02/2023, 7:43 PMgsr
11/02/2023, 7:43 PMgsr
11/02/2023, 7:43 PMgsr
11/02/2023, 7:44 PM{
"msg": "Your request for has been rejected.",
"status": "success",
"type": 2
}
Myka Forrest
11/02/2023, 7:58 PMr.msg
is a string, why does it need to be parsed?gsr
11/02/2023, 8:00 PMgsr
11/02/2023, 8:00 PMgsr
11/02/2023, 8:00 PMMyka Forrest
11/02/2023, 8:00 PMgsr
11/02/2023, 8:00 PMMyka Forrest
11/02/2023, 8:01 PMr.msg
gsr
11/02/2023, 8:01 PMgsr
11/02/2023, 8:02 PMMyka Forrest
11/02/2023, 8:03 PMMyka Forrest
11/02/2023, 8:03 PMr
the raw response or parsed?gsr
11/02/2023, 8:12 PMgsr
11/02/2023, 8:12 PMMyka Forrest
11/02/2023, 8:13 PMr
or parse()
in that fiddleMyka Forrest
11/02/2023, 8:14 PMgsr
11/02/2023, 8:38 PMgsr
11/02/2023, 8:38 PMgsr
11/02/2023, 8:39 PM{
"msg": "Your request for has been rejected.",
"status": "success",
"type": 2
}
gsr
11/02/2023, 8:39 PMMyka Forrest
11/02/2023, 8:39 PMMyka Forrest
11/02/2023, 8:40 PMgsr
11/02/2023, 8:40 PMconst submitAppRejForm = (e) => {
e.preventDefault(); // stop form submission
const clickedButton = e.submitter; // which submit?
if (clickedButton && clickedButton.name) {
const action = clickedButton.name;
let oFormData = new FormData(e.target);
$.ajax({
type: 'POST',
url: `TimeOff_Request_proc.cfm?action=${action}`,
data: oFormData,
contentType: false,
processData: false,
beforeSend: function(){
showLoadingScreen();
},
complete: function(){
$.unblockUI();
},
success: function (r) {
console.log(JSON.parse(r['msg']));
Swal.fire({
icon: 'success',
title: 'Cool',
text: r.msg
}).then((result) => {
window.location.reload();
});
},
error: function (xhr, status, error) {
clearInterval(processing);
$.unblockUI();
Swal.fire({
icon: 'error',
title: 'Oops...',
text: "AJAX request failed:" + error
});
// Add error handling logic here (e.g., display an error message)
}
});
}
}
Myka Forrest
11/02/2023, 8:40 PMgsr
11/02/2023, 8:40 PMgsr
11/02/2023, 8:40 PMMyka Forrest
11/02/2023, 8:41 PMr['msg']
doesn't exist if r
hasn't been parsedMyka Forrest
11/02/2023, 8:41 PMMyka Forrest
11/02/2023, 8:42 PMRyan Albrecht
11/02/2023, 8:42 PMsuccess: function (r) {
var data = JSON.parse(r);
Swal.fire({
icon: 'success',
title: 'Cool',
text: data.msg
}).then((result) => {
window.location.reload();
});
},
Ryan Albrecht
11/02/2023, 8:42 PMgsr
11/02/2023, 8:42 PMMyka Forrest
11/02/2023, 8:43 PMMyka Forrest
11/02/2023, 8:43 PMgsr
11/02/2023, 8:44 PMgsr
11/02/2023, 8:45 PMgsr
11/02/2023, 8:45 PMMyka Forrest
11/02/2023, 8:46 PMRyan Albrecht
11/02/2023, 8:46 PMsuccess: function (r) {
Swal.fire({
icon: 'success',
title: 'Cool',
text: r.msg
}).then((result) => {
window.location.reload();
});
},
gsr
11/02/2023, 8:46 PMRyan Albrecht
11/02/2023, 8:46 PMgsr
11/02/2023, 8:49 PMgsr
11/02/2023, 8:49 PMgsr
11/02/2023, 8:49 PMgsr
11/02/2023, 8:49 PM