A simple jQuery form submitting plugin.
<form id="form" action="json/request.json"> <div class="form-group"> <label for="inputName">Name</label> <input type="text" class="form-control" id="inputName" name="name"> </div> <div class="form-group"> <label for="inputEmail">Email</label> <input type="email" class="form-control" id="inputEmail" name="email"> </div> <div class="form-group"> <label for="inputComment">Comment</label> <textarea class="form-control" id="inputComment" name="comment" rows="6"></textarea> </div> <button type="submit" class="btn btn-primary">Submit</button> </form>
$(function () { var $body = $(document.body); var $form = $('#form'); var $name = $form.find('#inputName'); $form.submitter({ dataType: 'json', start: function (e) { if (!$name.val()) { e.preventDefault(); // Prevent submit $name.focus(); // Tooltip: https://github.com/fengyuanchen/tooltip $body.tooltip('Please enter a name', 'warning'); } }, done: function (e, data) { if ($.isPlainObject(data) && data.success) { $body.tooltip(data.result, 'success'); } }, fail: function (e, textStatus) { $body.tooltip(textStatus, 'danger'); } }); });