Ver Mensaje Individual
  #5 (permalink)  
Antiguo 13/06/2012, 22:27
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: limpiar select despues de enviar datos mediante ajax

dontexplain gracias por responder

intente adaptar lo que me indicas pero no logro limpiar el select despues de enviarlo

estoy utilizando jquery modal form

este es mi codigo

Código Javascript:
Ver original
  1. $(function() {
  2.         // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
  3.         $( "#dialog:ui-dialog" ).dialog( "destroy" );
  4.        
  5.         var name = $( "#name" ),
  6.             email = $( "#email" ),
  7.             telefono1 = $( "#telefono1" ),
  8.             telefono2 = $( "#telefono2" ),
  9.             fax = $( "#fax" ),
  10.             web = $( "#web" ),
  11.             comentario = $( "#comentario" ),
  12.            
  13.             allFields = $( [] ).add( name ).add( email ).add( telefono1 ).add( telefono2 ).add( fax ).add( web ).add( comentario ),
  14.            
  15.             tips = $( ".validateTips" );
  16.  
  17.         function updateTips( t ) {
  18.             tips
  19.                 .text( t )
  20.                 .addClass( "ui-state-highlight" );
  21.             setTimeout(function() {
  22.                 tips.removeClass( "ui-state-highlight", 1500 );
  23.             }, 500 );
  24.         }
  25.  
  26.         function checkLength( o, n, min, max ) {
  27.             if ( o.val().length > max || o.val().length < min ) {
  28.                 o.addClass( "ui-state-error" );
  29.                 updateTips( "Length of " + n + " must be between " +
  30.                     min + " and " + max + "." );
  31.                 return false;
  32.             } else {
  33.                 return true;
  34.             }
  35.         }
  36.  
  37.         function checkRegexp( o, regexp, n ) {
  38.             if ( !( regexp.test( o.val() ) ) ) {
  39.                 o.addClass( "ui-state-error" );
  40.                 updateTips( n );
  41.                 return false;
  42.             } else {
  43.                 return true;
  44.             }
  45.         }
  46.        
  47.         $( "#dialog-form" ).dialog({
  48.             autoOpen: false,
  49.             height: 600,
  50.             width: 350,
  51.             modal: true,
  52.             buttons: {
  53.                 "Create an account": function() {
  54.                     var bValid = true;
  55.                     allFields.removeClass( "ui-state-error" );
  56.  
  57.                     bValid = bValid && checkLength( name, "username", 3, 40 );
  58.                     bValid = bValid && checkLength( email, "email", 6, 80 );
  59.                    
  60.  
  61.                     //bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  62.                     // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  63.                     bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. [email protected]" );
  64.                     //bValid = bValid && checkLength( password, "password", 5, 16 );
  65.                     //bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
  66.                
  67.  
  68.                    
  69.                    
  70.                 var namec = $("#name").val();
  71.                 var emailc = $("#email").val();
  72.                 var telefono1c = $("#telefono1").val();
  73.                 var telefono2c = $("#telefono2").val();
  74.                 var faxc = $("#fax").val();
  75.                 var webc = $("#web").val();
  76.                 var categoriac = $("#categoria").val();
  77.                 var comentarioc = $("#comentario").val();    
  78.                  
  79.                     if ( bValid ) {
  80.                         /*$( "#users tbody" ).append( "<tr>" +
  81.                             "<td>" + name.val() + "</td>" +
  82.                             "<td>" + email.val() + "</td>" +
  83.                             "<td>" + password.val() + "</td>" +
  84.                         "</tr>" );*/
  85.                 $.ajax({
  86.                   url:'archivo.php',
  87.                   type:'post',
  88.                   data:'name='+namec+'&email='+emailc+'&telefono1='+telefono1c+'&telefono2='+telefono2c+'&fax='+faxc+'&web='+webc+'&categoria='+categoriac+'&comentario='+comentarioc,
  89.                   }).done(function() {
  90.                   cargar_usuarios();
  91.                
  92.                  });
  93.        
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.                         $( this ).dialog( "close" );
  104.                    
  105.                     }
  106.                 },
  107.                 Cancel: function() {
  108.                
  109.                     $( this ).dialog( "close" );
  110.                 }
  111.             },
  112.             close: function() {
  113.                 allFields.val( "" ).removeClass( "ui-state-error" );
  114.             }
  115.         });
  116.  
  117.         $( "#create-user" )
  118.             .button()
  119.             .click(function() {
  120.                 $( "#dialog-form" ).dialog( "open" );
  121.             });
  122.     });