$(document).ready(function(){ $('form').submit(function(evt){ evt.preventDefault(); var $this=$(this); if($this.attr("id")=="career_form"){ SubmitajaxForm($this); }else{ SubmitForm($this); } }); }); function SubmitajaxForm($this){ var data = new FormData($this[0]); var uri=$this.attr('action'); $("#careerFrm").attr('disabled','true'); $.ajax({ type: "POST", enctype: 'multipart/form-data', url: uri, data: data, processData: false, contentType: false, cache: false, timeout: 600000, success: function (response) { response=JSON.parse(response); $this.find('button').removeAttr('disabled'); if(response.attribute.redirect){ $(location).attr('href',response.attribute.destination); // window.open(response.attribute.destination); } else{ alert(response.message); $this[0].reset(); console.log(response.message); $(".fancybox-close-small").click(); } }, error: function (e) { $("#result").text(e.responseText); console.log("ERROR : ", e); $("#btnSubmit").prop("disabled", false); } }); } function SubmitForm($this){ $this.find('button').attr('disabled', 'true'); //$('.lds-spinner-loder').show(); var uri=$this.attr('action'); var request =$this.serializeArray(); request.push({ "name": "id", "value": $this.attr('id') }); $.post(uri,request).done(function(response){ response=JSON.parse(response); if(!response.success){ //$this.find('button').removeAttr('disabled'); alert(response.message); if(response.status=='ALERDSUBMITED'){ $this[0].reset(); } return false; } if(response.attribute.nexttab){ $(response.attribute.previous).removeClass('active'); $(response.attribute.previousedatatab).removeClass('current'); $(response.attribute.next).addClass('active'); $(response.attribute.nextdatatab).addClass('current'); $(response.attribute.previous).on('click'); } if(response.attribute.redirect){ $(location).attr('href',response.attribute.destination); }else{ alert(response.message); $this[0].reset(); $this.find('button').removeAttr('disabled'); } }); }