X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F90-form.js;h=a30e7f4fc81f68c1aa3b25a9bebde8c04f099b90;hb=dee46c5bb42f8fdaa70e70d6bdd4da5072a99ecd;hp=a326ca888752f045a8b9760844901d539d1b7da0;hpb=eef56f7a0a705023eae000009947e42014dfaefe;p=plack-app-gruntmaster.git diff --git a/js/90-form.js b/js/90-form.js index a326ca8..a30e7f4 100644 --- a/js/90-form.js +++ b/js/90-form.js @@ -1,21 +1,15 @@ -(function(){ - 'use strict'; - - $( document ).ready(function(){ - $('.jsform').on('click', 'input[type="submit"]', function(e){ - var form_data = new FormData(this.parentElement); - var form = $(this).parent(); - var xhr = new XMLHttpRequest(); - xhr.open(form.attr('method'), form.attr('action')); - xhr.onload = function() { - $('#result').html(this.responseText); - }; - xhr.onerror = function() { - $('#result').html('Error!'); - }; - $('#result').html('Loading...'); - xhr.send(form_data); - return false; - }); +$(function(){ + const result = q('#result'); + $('.jsform > input[type="submit"]').on('click', e => { + const form_data = new FormData(this.parentElement); + const form = this.parentNode; + const xhr = new XMLHttpRequest(); + xhr.open(form.getAttribute('method'), form.getAttribute('action')); + xhr.onload = () => result.innerHTML = this.responseText; + xhr.onerror = () => result.innerHTML = 'Error!'; + window.scrollTo(0, 0); + result.innerHTML = 'Loading...'; + xhr.send(form_data); + e.preventDefault(); }); -})(); +});