I am facing an issue with a form that I intend to use only for an AJAX call. The AJAX call is triggered on submit in order to utilize the auto-check feature for required fields. Despite returning false on submit, the form still submits. Surprisingly, when I comment out the statement responsible for the AJAX call, the form does not submit. Below is the code snippet of the form I am using. Any ideas why I can't prevent form submission?
<form action="" method="post" onsubmit="ajaxReq (); return false;">
<input type="hidden" name="type" value='something'>
<input type="text" name="testText" required>
<input type="submit" value="AJAX_TEST">
</form>
Below is the ajaxReq function:
//I will be using the data from the form inside data as the data of the ajax call
//Currently data in the form is ignored
function ajaxReq() {
var ajaxSettings = {
'url' : '',
'async' : false,
'type' : 'POST',
'data' : {
'type' : 'SOME_TYPE'
},
'success' : function(data) {
data = JSON.parse(data);
//emptying this part did not change the result
//will be using data here
}
};
$.ajax(ajaxSettings);
return false;
}