I have written an ajax post request however it seems to be executing multiple times. The first time I click the button it will execute only once, however the second time I click the button it will run through the code twice, three times will execute three times and so on. I am not sure what is causing this problem, here is my ajax post request. If any other information is needed I will happily provide.
$(document).ready(function () {
$('#postEditDatasource').click(function (event) {
//serialise and assign json data to hidden field
$('#dsDeletedDP').val(JSON.stringify(deleted));
$('#dsEditedDP').val(JSON.stringify(editDPArr));
//get the form
var form = $('#__dsAjaxAntiForgeryForm');
var URL = 'Settings/EditDatasource';
$('#__dsAjaxAntiForgeryForm').on('submit', function () {
$.ajax({
url: URL,
data: form.serialize(),
type: 'POST',
success: function (result) {
reloadPostEditAction($('#dsID').val());
if (deletedDatapoints != null) {
DeleteFromTable(deleted);
}
//clear all values from hidden inputs
$('input:hidden').each(function () {
if ($(this).attr('name') != '__RequestVerificationToken' && $(this).attr('id') != 'dsID') {
$(this).val('');
}
});
$('#dsEditedDP').val('');
ShowDatasourcePostAlert('#successPost', 3000);
},
error: function (jqXHR, textStatus, errorThrown) {
//alert(jqXHR + ', ' + textStatus + ', ' + errorThrown);
ShowDatasourcePostAlert('#successPost', 3000);
}
})
return false;
})
});
})