I am using form with onsubmit tag. And in onsubmit function i will call ajax and i will return true in success function and false in error section. But always form has been submitted.
html
<form action="/" method="post" onsubmit="return formsubmit()">
script
function formsubmit() {
"use strict";
var isBasic = $(".test").val() //this is hidden element
if (isBasic === "true") {
return true;
}
if (isBasic === "false") {
$.ajax({
type: "post",
url: "/",
data: "sample",
success: function (data) {
if (data.success) {
return true;
}
if (!data.success) {
return false;
}
},
error: function () {
}
});
}
}
}
this doesnt work for me. always form submitted. Please help me to resolve this.