$(function() { // Get the form. var form = $('#idForm'); var formMessages = $('#form-messages'); // console.log("helo2:"); // Set up an event listener for the contact form. $(form).submit(function(e) { // Stop the browser from submitting the form. e.preventDefault(); // Serialize the form data. var formData = $(form).serialize(); // Submit the form using AJAX. $.ajax({ type: 'POST', url: $(form).attr('action'), data: formData }) .done(function(response) { // Make sure that the formMessages div has the 'success' class. //console.log("helo:"); console.log(response); $(formMessages).removeClass('error'); $(formMessages).addClass('success'); // Set the message text. $(formMessages).html(response); $(formMessages).show(); document.getElementById('form-messages').focus(); setTimeout(function() { window.location = "https://braina.me/login/?newaccount"; }, 1000); // $(formMessages).html(response['msg']); // window.location = "https://braina.me/login/?newaccount"; }) .fail(function(data) { // Make sure that the formMessages div has the 'error' class. $(formMessages).removeClass('success'); $(formMessages).addClass('error'); //console.log("failresponse:"+data); // Set the message text. if (data.responseText !== '') { $(formMessages).html(data.responseText); } else { $(formMessages).html('Oops! An error occurred and your credentials could not be validated. Contact Support.'); } $(formMessages).show(); $(formMessages).fadeIn(1000); document.getElementById('form-messages').focus(); if(data.responseText.indexOf("Please try again") > -1) { location.reload(); //grecaptcha.reset(); } }); }); });