I've tried many of the other solutions to this problem on SO, and elsewhere, but I can't seem to prevent my form from submitting twice. Here is the code that I'm currently having this issue with:
$(function() {
var additemtoform = $('#additemform');
$("#additemform .addbtn").on("click", function(e) {
e.preventDefault();
function handleData( responseData ) {
if ($(responseData).find('#repitems').length) {
var replacement = $('<div />').html(responseData).find('#repitems').html();
$('#test').html(replacement);
} else {
additemtoform.submit();
}
}
$.ajax({
type: 'POST',
url: 'WebCatPageServer.exe',
dataType: 'html',
cache: false,
data: additemtoform.serialize(),
beforeSend: function() {},
success: function(data) {
handleData(data);
},
error: function() {
alert('error');
}
});
return false;
});
});
If I remove the submit in the callback, then the form doesn't submit at all. So, what am I missing?
Thanks!
Aucun commentaire:
Enregistrer un commentaire