JSFiddle - React, Tailwind, and code Playground
by ajpiano
HTML
<form id="myform">
<input type="text" id="sec_effortid" value="foo">
<button type="submit">Submit</button>
</form>
JavaScript
var GOODRESPONSE = JSON.stringify({
effort: true
}),
BADRESPONSE = JSON.stringify({
effort:false
});
var f = $("#myform").submit(function(e) {
e.preventDefault();
$.post("/echo/json/",{json:Math.random() < .5 ? GOODRESPONSE : BADRESPONSE}, function(response){
if(response.effort == true){
alert("it's valid! i will now trigger the native submit on the form!");
f[0].submit()
} else {
alert("it's invalid");
}
},"json");
});