jquery - Validating a form with ajax json response -


i sending form server before sending form make ajax request returns json response. problem is, if condition valid ask user if still want send form, sends form if user says no.

this code

$("#form-alta-servicios").submit(function(){ if( confirm('desea enviar la informacion ahora?') ) {   //entonces validamos datos   if( $('#tel').val()=='')   {     alert('ingresa el numero de telefono');     $('#tel').focus()     return false;   }   else   {     if( $('#dir').val()== '' )     {       alert('la direccion es un dato requerido');       $("#dir").focus();       return false;     }     else     {       if( $("#taxi_id option:selected").val()=='0' )       {         alert('seleccione un taxi por favor');         return false;       }       else       {         $.ajax(         {           type: 'get',           url: '/verifica-si/'+$("#taxi_id option:selected").val()+'/servicio',                         data: {},                         success: function(data)           {             if(data['msj']=='encontrado')             {               if(confirm('existe un servicio, desea terminarlo y empezar uno nuevo'))               {                 return true;               }               else               {                 return false;               }             }           },           datatype: 'json'                   });   //fin solicitud ajax              }     }   } } else {   return false; } 

});

the part question

success: function(data)           {             if(data['msj']=='encontrado')             {               if(confirm('existe un servicio, desea terminarlo y empezar uno nuevo'))               {                 return true;               }               else               {                 return false;               }             }           }, 

if confirm true must send form, if false must stop sending form, still sending it.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -