'If the condition is false stop the script in JQuery
In the code below, the pop up is appearing but the AJAX part is also getting executed.
What I want here is, if the pop-up $('#confirmCloseFutureEvent').modal('show'))
is executed I do not want the $.ajax
call to run. I want AJAX to run if ref == true
. How can I do this?
function checkFutureEvents() {
var result = false;
$('.event-form-edit').each(function() {
$endEventDateTime = $(this).find('.eventEndDateTime').val();
$endEventDates = $endEventDateTime.substring(0, $endEventDateTime.lastIndexOf(' '));
$currentDate = moment(new Date(), 'MM/DD/YYYY').format('MM/DD/YYYY');
$endEventDate = moment($endEventDates, 'MM/DD/YYYY').format('MM/DD/YYYY');
$eventStatus = $(this).find('.event-status option:selected').text();
if ($eventStatus == 'Closed' && $endEventDate > $currentDate) {
$('#confirmCloseFutureEvent').modal('show');
$('#close-future-event').on('click', function() {
listenerSaveModuleJob($(this));
});
result = false;
} else {
result = true;
}
});
return result;
}
$('#btn').on('click', function() {
listenerSaveModuleJob();
});
function listenerSaveModuleJob($elt) {
var res = checkFutureEvents();
if (res == false) {
return false;
}
$form = $elt.closest('.panel-default').find('form[class="job_modules"]');
$.ajax({
type: 'POST',
cache: false,
url: $form.data('action'),
data: formSerialize,
success: function(data) {
//do-something
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|