Ver Mensaje Individual
  #7 (permalink)  
Antiguo 06/07/2010, 20:36
Avatar de after
after
 
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 11 meses
Puntos: 10
Respuesta: envio de datos formulario a php con jquery

Cita:
Iniciado por Dany_s Ver Mensaje
podes ocupar el método serialize
http://api.jquery.com/serialize/
He buscado y encontré que serialize lo usan con forms, pero yo en esta ocasión no estoy usando ningún form

Lo que hace el script es enviarlo al hacer click en el botón

Código Javascript:
Ver original
  1. $('#post').live('click', function(){
  2.            
  3. $.ajax({
  4.     type: 'POST',
  5.    data: 'texto='+$(this).parent().find('textarea').val(),
  6.     url: 'receptor.php',
  7.    
  8.    
  9.     success: function(data){
  10.       alert( "Su comentario fue agregado: : " + data );
  11.  
  12.     }
  13. });
Intente usar un form pero para eso también tendría que insertar un Botón para que en una función .submit(function(){... lo envíe. Pero con jquery ya le tengo un botón.

Pongo todo el código completo.


<
Código Javascript:
Ver original
  1. script>
  2.  
  3.     $(function(){
  4.         $('#facebook').val('').blur().focus(function(){
  5.             if($(this).data('facebook')) return false;
  6.             $(this).data('facebook', true);
  7.             $(this).css({
  8.                 width   : $(this).outerWidth() - 36
  9.             });
  10.             $('<img src="images/facebook.gif" class="avatar" style="margin-top:1px;position:absolute;"/>'+
  11.                     '<span class="avatar" style="display:inline-block;width:36px;height:30px"></span>').insertBefore($(this));
  12.             $('<img src="images/facebook_comment.png" class="avatar" id="post" style="float:right;cursor:pointer;margin-top:2px" />').insertAfter($(this));
  13.         });
  14.         $('#post').live('click', function(){
  15.            
  16. $.ajax({
  17.     type: 'POST',
  18.    data: 'texto='+$(this).parent().find('textarea').val(),
  19.     url: 'receptor.php',
  20.    
  21.    
  22.     success: function(data){
  23.       alert( "Su comentario fue agregado: : " + data );
  24.  
  25.     }
  26. });
  27.  
  28.  
  29.  
  30.             var clone = $(this).parent().clone();
  31.             var txt = $(document.createElement('span')).html('<b style="color:#3B5998">Facebook</b> '+$(this).parent().find('textarea').val()).css({
  32.                 display     : 'inline-block',
  33.                 width       : $(this).parent().find('textarea').width(),
  34.                 overflow    : 'hidden'
  35.             });
  36.                    
  37.             txt.insertBefore(clone.find('textarea'));
  38.             clone.insertBefore($(this).parent()).find('textarea').remove();
  39.             clone.find('#post').remove();
  40.             $(this).parent().find('textarea').val('').blur();
  41.            
  42.            
  43.            
  44.         });
  45.  
  46.    
  47.     });
  48.    
  49. </script>
__________________
@ivancamiloGo