JSFiddle - React, Tailwind, and code Playground

by Brad Christie

HTML

<form action="http://www.google.com/">
    Query: <input type="text" name="q" id="q" />
    <input type="submit" value="Search" />
</form>

JavaScript

$(function(){
    // bind to the submit button
    $('form input[type=submit]').click(function(e){
        // pseudo-aajax "success" callback:
        setTimeout(function(){
            
            // make up sample ajax return data
            var data = {
                success: false
            };
            
            // it was a "success"
            if (data.success){
                // now submit the form
                $('form').submit();
            }else{
                // show errors in form
                $('form').append('Validation Failed');
            }
        },1000);
        
        // always prevent the submit
        e.preventDefault();
    });
});