Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/12/2012, 01:31
elfeme
 
Fecha de Ingreso: abril-2010
Ubicación: Argentina
Mensajes: 57
Antigüedad: 14 años, 1 mes
Puntos: 1
[Problema] Ajax funciona solo una vez

Bueno gente, vi una cantidad de post por forosdelweb con el mismo problema, pero aun así, no lo pude solucionar.
El tema es que estoy haciendo un login con ajax y jquery, y funciona solo la primera vez, luego te recarga toda la página.

Les dejo el código:

Código Javascript:
Ver original
  1. var x = $(document);
  2. x.ready (function () {
  3.     var login = $('#login-form');
  4.     login.stop(true).hover (function () {
  5.             login.stop(true).animate({
  6.                 'margin-top' : '0'
  7.             })
  8.         },
  9.         function () {
  10.             login.stop(true).animate({
  11.                 'margin-top' : '-160'
  12.             })
  13.         }
  14.     )
  15.    
  16.     var submit = $('#submit');
  17.     submit.click (function () {
  18.         var user = $('#user').attr('value');
  19.         var passwd = $('#passwd').attr('value');
  20.         var profile = $('#profile');
  21.         $.ajax ({
  22.             async: true,
  23.             type: 'POST',
  24.             dataType: 'html',
  25.             contentType: 'application/x-www-form-urlencoded',
  26.             url: 'login.php',
  27.             data: 'user='+user+'&passwd='+passwd,
  28.             beforeSend: function () {
  29.                 $('#login-form form').html('<p><img src="images/weed.gif" title="weed" alt="weed"/></p>');
  30.             },
  31.             success: function (datos) {
  32.                 if (datos.indexOf('incorrectos') != -1) {
  33.                     $('#login-form').html(datos);
  34.                 } else {
  35.                     $('#login').html(datos);
  36.                 }
  37.             },
  38.             timeout: 4000,
  39.             error: function () {
  40.                 login.text('Problemas en el servidor. Intente más tarde.');
  41.             }
  42.         });
  43.         return false;
  44.     })
  45.    
  46.     var logout = $('#logout');
  47.     logout.click (function () {
  48.         $.ajax ({
  49.             async: true,
  50.             type: 'POST',
  51.             dataType: 'html',
  52.             contentType: 'application/x-www-form-urlencoded',
  53.             url: 'logout.php',
  54.             beforeSend: function () {
  55.                 $('#profile').html('<p><img src="images/weed.gif" title="weed" alt="weed"/></p>');
  56.             },
  57.             success: function(datos) {
  58.                 $('#profile').html('');
  59.                 $('#login').html(datos);
  60.             },
  61.             timeout: 4000,
  62.             error: function () {
  63.                 login.text('Problemas en el servidor. Intente más tarde.');
  64.             }
  65.         });
  66.         return false;
  67.     })
  68.    
  69. })

y la web para que vean de lo que hablo, intenten loguearse 2 veses y van a ver lo que pasa.

http://feme.zapto.org/faso/
__________________
Blog de Informatíca y Tecnología ;)