I have a problem with the code below. I can’t get it to popup the alert on submit. Well the only way I got it to work was by inserting another alert outside of $.get. (you can see it below). I’ll be more than thankful for any help and guidelines I might get.
$('#addEvent').submit(function() {
var date = $('#day').val();
var startTime = $('#startTime').val();
$.get("/cal/check-For-Existing-Events/time/"+date+"%20"+startTime+":00/room/1234", function(data) {
if(data == "Error: date") {
alert('Error: This date has expired.');
return false;
}
else if(data == "Error: existing") {
alert('Error: You already have a reservation made on this day.')
return false;
}
else {
return true;
}
});
alert('test'); //If I remove this part, above errors don't work. WTH!?
});
Thank you all for your suggestions. I tried all of them but none of them seemed to work. That’s why I decided to start from scratch using some of the information I got from previous answers.
Below is the code that works. + I also have to add, that I had to remove the submit button from the form and make another one outside of it for code to work. I Don’t really know why, so if anyone has any information on this.. do tell. 🙂
I hope that this answer will be helpful to anyone. Cheers! 🙂