$(document).ready(function(){ console.log("# READY"); $('#BotConsulta').click(function(){ $('#FrmConsulta').submit(); return false; }); }); $('#FrmConsulta').submit(function(e){ e.preventDefault(); if(!$("#CheckLegal").prop('checked')) { if ($("#HiddeLanguage").length) { $("#TextoPopup").html("Please, read and accept privacy conditions"); } else { $("#TextoPopup").html("Por favor, lea y acepte el Aviso Legal y Condiciones de Privacidad."); } $("#Popup").show(); return; } $.ajax({ type: "POST", url: "https://dataprius.com/amb.consulta/", data: $(this).serialize(), datatype : 'html', success: function(data) { if(strStartsWith(data,"error:")) { var arrResult= data.split(":"); var msg=arrResult[1]; console.log("# ERROR"); $("#TextoPopup").html(msg); $("#Popup").show(); } else { $("#ValNombre").val(""); $("#ValEmail").val(""); $("#ValConsulta").val(""); if ($("#HiddeLanguage").length) { $("#TextoExito").html("Your question has been sent.
We will respond shortly."); } else { $("#TextoExito").html("Su consulta ha sido enviada.
Le responderemos en breve."); } $("#PopupExito").show(); } } }); return false; }); function strStartsWith(str, prefix) { return str.indexOf(prefix) === 0; }