Foros del Web » Programando para Internet » Javascript » Frameworks JS »

href con ajax??

Estas en el tema de href con ajax?? en el foro de Frameworks JS en Foros del Web. Saludos a todos soy nuevo en esto del ajax,y tengo un este pekeño codigo @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original $. ajax ( { ...
  #1 (permalink)  
Antiguo 26/04/2010, 11:30
 
Fecha de Ingreso: abril-2010
Mensajes: 115
Antigüedad: 14 años
Puntos: 2
Exclamación href con ajax??

Saludos a todos soy nuevo en esto del ajax,y tengo un este pekeño codigo
Código Javascript:
Ver original
  1. $.ajax({
  2.         url:'login.php',
  3.         type:'post',
  4.         data: "username="+username+"&password="+password+"&rememberme="+rememberme,
  5.         success: function(msg){
  6.             if (msg==0)
  7.             {          
  8.                 $('#result').fadeIn('slow');
  9.                 $(".result-inner").html('<div class="forgott_pass">Informacion Incorrecta! <a href="mail.php" title="Forgot password"> Olvido Su Contraseña? </a></div>');
  10.                 //alert ("username="+username+"&password="+password);
  11.             }
  12.             if (msg==1){
  13.    
  14.         window.location.href="alumnos.php";
  15.             }
  16.            
  17.         }
  18.     });
y quiero saber si es posible que en el HREF mandarle una variable como en php... ago asi como

<a href="mail.php?username="username>

si alguien me pudiera asesorar se los agradeceria muchisimo

gracias
  #2 (permalink)  
Antiguo 27/04/2010, 11:36
 
Fecha de Ingreso: agosto-2009
Ubicación: capital federal
Mensajes: 39
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: href con ajax??

hola mira en ajax hay 2 formas tambien de pasar datos get y post como en php por ejemplo este es una manera de pasar por post
Código HTML:
Ver original
  1.     <script type="text/javascript">
  2.         var xhr;
  3.             function startAjax(){
  4.                 if(window.ActiveXObject){
  5.                     xhr=new ActiveXObject("Microsoft.XMLHTTP");
  6.                     //alert("entre en microsoft");
  7.                 }else if(window.XMLHttpRequest){
  8.                     xhr=new XMLHttpRequest();
  9.                     //alert("Entre en Firefox");
  10.                 }else{
  11.                     //alert("su navegador no soporta ajax");
  12.                 }
  13.                
  14.                 var m=document.getElementById('mail').value
  15.                 xhr.open("POST","mail.php");
  16.                 xhr.onreadystatechange=callback;
  17.                 xhr.setRequestHeader('Content-type','application/x-www-forn-urlencoded');
  18.                 xhr.send("mail="+m);
  19.             }
  20.             function callback(){
  21.                 if(xhr.readyState==4){
  22.                     if(xhr.status==200){
  23.                         alert(xhr.responseText);
  24.                 }
  25.                 //alert(xhr.responseText);
  26.                 var div=document.getElementById("mensaje");
  27.                 div.innerHTML=xhr.responseText;
  28.                 }
  29.             }
  30.     </script>
  31.         <input type="text" name="mail" id="mail">
  32.         <input type="button" value="enviar" onclick="startAjax()">
  33.         <div id="mensaje"></div>
  34. </html>


y si no por get que es mas facil
Código HTML:
Ver original
  1.     <script type="text/javascript">
  2.         var xhr;
  3.             function startAjax(){
  4.                 if(window.ActiveXObject){
  5.                     xhr=new ActiveXObject("Microsoft.XMLHTTP");
  6.                     //alert("entre en microsoft");
  7.                 }else if(window.XMLHttpRequest){
  8.                     xhr=new XMLHttpRequest();
  9.                     //alert("Entre en Firefox");
  10.                 }else{
  11.                     //alert("su navegador no soporta ajax");
  12.                 }
  13.                
  14.                 var m=document.getElementById('mail').value
  15.                 xhr.open("get","mail.php?mail="+m);
  16.                 xhr.onreadystatechange=callback;
  17.                 xhr.send(null);
  18.             }
  19.             function callback(){
  20.                 if(xhr.readyState==4){
  21.                     if(xhr.status==200){
  22.                         alert(xhr.responseText);
  23.                 }
  24.                 //alert(xhr.responseText);
  25.                 var div=document.getElementById("mensaje");
  26.                 div.innerHTML=xhr.responseText;
  27.                 }
  28.             }
  29.     </script>
  30.         <input type="text" name="mail" id="mail">
  31.         <input type="button" value="enviar" onclick="startAjax()">
  32.         <div id="mensaje"></div>
  33. </html>

saludos espero q te sirva!!
  #3 (permalink)  
Antiguo 27/04/2010, 16:30
 
Fecha de Ingreso: abril-2010
Mensajes: 115
Antigüedad: 14 años
Puntos: 2
Respuesta: href con ajax??

Muchas Grancias Lo intentare

Etiquetas: ajax, href
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:00.