/** * * * * */ var GLOB = { form:false } $(document).ready(function(){ GLOB.form = $(document.forms["pttncnts"]) $("#bttn-go").on("click",function(){sendData();}) }); function getFormData() { var data = GLOB.form.serialize(); return data ; } function sendData() { var privacy = false ; var data = getFormData(); var action = "actions/sendRequest.php" ; var lang = GLOB.form[0].lang.value ; if( $("#bttn-go").hasClass("disabled") ) { return ; } privacy = GLOB.form[0].privacy if( !privacy.checked ) { $("#privacy-error").show(); return ; } $("#bttn-go").addClass("disabled") ; $("#privacy-error").hide(); $("#send-error").hide(); if( lang!="it" ){ action = "../"+action ; } else{ action = "./"+action; } jQuery.ajax({ url : action , cache : false , data : data , type : "post" , dataType : "json" , success : function(response){handleResponse(response);} , error : function(response){handleResponse(response.responseText);} }) } function handleResponse(response) { console.log(response) if( typeof response !="object" ) { $("#send-error").show(); } else { if( !response.result ) { $("#send-error").show(); } else { GLOB.form.hide(); $("#send-ok").show(); } } $("#bttn-go").removeClass("disabled") ; }