Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/05/2012, 23:41
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: Consulta ajax

amigos gracias por responder estoy intentando implementar el codigo me resultan varios inconvenientes:

el siguiente codigo sirve para abrir el dialog modal form
Código Javascript:
Ver original
  1. <script>
  2.     $(function() {
  3.         // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
  4.         $( "#dialog:ui-dialog" ).dialog( "destroy" );
  5.        
  6.         var name = $( "#name" ),
  7.             email = $( "#email" ),
  8.             password = $( "#password" ),
  9.             allFields = $( [] ).add( name ).add( email ).add( password ),
  10.             tips = $( ".validateTips" );
  11.  
  12.         function updateTips( t ) {
  13.             tips
  14.                 .text( t )
  15.                 .addClass( "ui-state-highlight" );
  16.             setTimeout(function() {
  17.                 tips.removeClass( "ui-state-highlight", 1500 );
  18.             }, 500 );
  19.         }
  20.  
  21.         function checkLength( o, n, min, max ) {
  22.             if ( o.val().length > max || o.val().length < min ) {
  23.                 o.addClass( "ui-state-error" );
  24.                 updateTips( "Length of " + n + " must be between " +
  25.                     min + " and " + max + "." );
  26.                 return false;
  27.             } else {
  28.                 return true;
  29.             }
  30.         }
  31.  
  32.         function checkRegexp( o, regexp, n ) {
  33.             if ( !( regexp.test( o.val() ) ) ) {
  34.                 o.addClass( "ui-state-error" );
  35.                 updateTips( n );
  36.                 return false;
  37.             } else {
  38.                 return true;
  39.             }
  40.         }
  41.        
  42.         $( "#dialog-form" ).dialog({
  43.             autoOpen: false,
  44.             height: 300,
  45.             width: 350,
  46.             modal: true,
  47.             buttons: {
  48.                 "Create an account": function() {
  49.                     var bValid = true;
  50.                     allFields.removeClass( "ui-state-error" );
  51.  
  52.                     bValid = bValid && checkLength( name, "username", 3, 16 );
  53.                     bValid = bValid && checkLength( email, "email", 6, 80 );
  54.                     bValid = bValid && checkLength( password, "password", 5, 16 );
  55.  
  56.                     bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  57.                     // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  58.                     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]" );
  59.                     bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
  60.  
  61.                  
  62.                     if ( bValid ) {
  63.                         $( "#users tbody" ).append( "<tr>" +
  64.                             "<td>" + name.val() + "</td>" +
  65.                             "<td>" + email.val() + "</td>" +
  66.                             "<td>" + password.val() + "</td>" +
  67.                         "</tr>" );
  68.            
  69.                         $( this ).dialog( "close" );
  70.                    
  71.                     }
  72.                 },
  73.                 Cancel: function() {
  74.                     $( this ).dialog( "close" );
  75.                 }
  76.             },
  77.             close: function() {
  78.                 allFields.val( "" ).removeClass( "ui-state-error" );
  79.             }
  80.         });
  81.  
  82.         $( "#create-user" )
  83.             .button()
  84.             .click(function() {
  85.                 $( "#dialog-form" ).dialog( "open" );
  86.             });
  87.     });
  88.     </script>



estoy tratando de guardar en base de datos por tal motivo utilizo ajax pero no me funciona,este codigo ajax lo coloco en entre

if ( bValid ) {


$( this ).dialog( "close" );

}


Código Javascript:
Ver original
  1. $.ajax({
  2.               url:'archivo.php',
  3.                   type:'post',
  4.                   data:'name='+name+'&email='+email+'&password='+password,
  5.                   }).done(function(data) {
  6.                
  7.                alert(name+" "+email+" "+password);
  8.                
  9.    
  10.                   })

que estoy haciendo mal?