I am trying to create a popup modal that will display text echoed from a php submission script. So far it works for a success and prints the echoed content but I also want to catch echoed messages when an exception occurs in the php script.
popnotify is a seperate js function that takes text input and displays the modal with the text as a paragraph.
createuser.php
try:
......
echo 'Successfully created a new user';
}
catch (PDOException $ex){
echo "Something went wrong when creating a new user";
http_response_code(403);
die();
}
.js
jQuery("#load_form").on("click","#create_submit",function(event){
event.preventDefault();
var to_submit = $("#s_form").serialize();
var formLink = $("#s_form").attr('action');
jQuery('#load_form').find('input, select, button').prop('disabled', true);
$.post(formLink,to_submit)
.done(function(data){
popnotify_success(data);
})
.fail(function(data){
popnotify_fail(data);
})
.always(function(){
jQuery('#load_form').find('input, select, button').prop('disabled', false);
}); });