The Ajax call is working without using the alert confirmation. but when I added the alert confirmation the ajax call didn’t respond and I don’t know where is the problem.
<link rel="stylesheet" href="jquery-confirm.min.css">
<script src="jquery-confirm.min.js"></script>
<form id="add-offer">
<input type="number" name="offer" class="form-control price_offered" value="" step="any">
<button class="btn btn-primary" type="submit"> Add offer </button>
</form>
$("#add-offer").on('submit', function(e) {
e.preventDefault();
$.alert({
title: 'Confirmation ',
content: ' Are you sure.... bla bla bla? ',
rtl: true,
closeIcon: true,
buttons: {
confirm: {
text: 'Confirm ',
btnClass: 'btn-blue',
action: function() {
$.ajax({
type: 'POST',
url: 'ajax/add-offer.php',
data: new FormData(this),
dataType: 'json',
contentType: false,
cache: false,
processData: false,
beforeSend: function() {},
success: function(response) {
console.log(response);
if (response.success == 1) {
alert(response.message);
} else {
alert(response.message);
}
}
});
}
},
cancel: {
text: 'Cancel ',
action: function() {}
}
}
});
});
2
Answers
Replace
$.alert({
withalert({
See jsfiddle.net/msteel9999/eyk0q37d/3
This might be an issue with the function block context. You can set the data variable to get the
e.target
as the Form Data parameter and try. Check the code below: