When a user clicks on a date field and enters a date, a post request is sent. But then when the user clicks somewhere off the field, the request sends a second time. How do I correct this? I tried focusout() but the problem persists.
$(".cInput").focusout(function(){
var fieldName = this.name;
var fieldValue = this.value;
var cid = $('meta[name="cid"]').attr('content');
var cnum = $('meta[name="cnum"]').attr('content');
$.ajax({
/* the route pointing to the post function */
url: '/cUpdate',
type: 'POST',
/* send the csrf-token and the input to the controller */
data: {_token: CSRF_TOKEN, moduleID: $("#moduleID").text(), checkName: fieldName, checkValue: fieldValue, cid: cid, cnum: cnum},
dataType: 'JSON',
/* remind that 'data' is the response of the AjaxController */
success: function (data) {
window.history.replaceState({}, document.title, thisURL);
}
});
});