Ir al contenido


Foto

Ajax no hace la llamada a php


  • Por favor identifícate para responder
22 respuestas en este tema

#1 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 01 noviembre 2012 - 02:37

Hola, por favor me podeis decir porque este cod ajax no hace la llamada del archivo getClient.php.

[js]
  <script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">

var ajax = new sack();

var currenttelefono=false;

function getClientData()

{

var telefono = document.getElementById('telefono').value.replace(/[^0-9]/g,'');

if(telefono.length==9 && telefono!=currenttelefono){

currenttelefono = telefono

ajax.requestFile = 'getClient.php?gettelefono=' telefono; // Specifying which file to get

ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found

ajax.runAJAX(); // Execute AJAX function

}



}



function showClientData()

{

var formObj = document.forms['clientForm'];

eval(ajax.response);

}





function initFormEvents()

{

document.getElementById('telefono').onblur = getClientData;

document.getElementById('telefono').focus();

}

window.onload = initFormEvents;

</script>


Gracias y un saludo
[/js]
  • 0

#2 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 01 noviembre 2012 - 03:23

te marca algún error?
  • 0

#3 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 01 noviembre 2012 - 03:28

Hola, como estas....
No me da ningún error simplemente no hace nada.
Te pongo todo:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento sin título</title>
<style type="text/css">

body{

background-repeat:no-repeat;

font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;

height:100%;

background-color: #FFF;

margin:0px;

padding:0px;

background-image:url('/images/heading3.gif');

background-repeat:no-repeat;

padding-top:85px;

}



fieldset{

width:500px;

margin-left:10px;

}



</style>

    <script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">

var ajax = new sack();

var currenttelefono=false;

function getClientData()

{

var telefono = document.getElementById('telefono').value.replace(/[^0-9]/g,'');

if(telefono.length==9 && telefono!=currenttelefono){

currenttelefono = telefono

ajax.requestFile = 'getClient.php?gettelefono=' telefono; // Specifying which file to get

ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found

ajax.runAJAX(); // Execute AJAX function

}



}



function showClientData()

{

var formObj = document.forms['clientForm'];

eval(ajax.response);

}





function initFormEvents()

{

document.getElementById('telefono').onblur = getClientData;

document.getElementById('telefono').focus();

}

window.onload = initFormEvents;

</script>
</head>

<body>
<form name="clientForm" action="ajax-client_lookup.html" method="post">

<fieldset>

<legend>Client information</legend>

<table>

<tr>

<td><label for="telefono">Nº Teléfono:</label></td>

<td><input name="telefono" id="telefono" size="9" maxlength="9"></td>

</tr>

<tr>

<td><label for="nombre">First name:</label></td>

<td><input name="nombre" id="nombre" size="20" maxlength="255"></td>

</tr>

<tr>

<td><label for="apellidos">Last name:</label></td>

<td><input name="apellidos" id="apellidos" size="20" maxlength="255"></td>

</tr>

</table>

</form>

</fieldset>


</body>
</html>



getClient.php

<?php
/* Replace the data in these two lines with data for your db connection */
$connection = mysql_connect("localhost","root","root"); 
mysql_select_db("pruebas",$connection);

if(isset($_GET['gettelefono'])){ 
  $res = mysql_query("select * from usuarios where telefono='".$_GET['gettelefono']."'") or die(mysql_error());
  if($inf = mysql_fetch_array($res)){
    echo "formObj.nombre.value = '".$inf["nombre"]."';\n";   
    echo "formObj.apellidos.value = '".$inf["apellidos"]."';\n";   
   
  }else{
    echo "formObj.nombre.value = '';\n";   
    echo "formObj.apellidos.value = '';\n";   
 
  }   
}
?>


Gracias
  • 0

#4 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 01 noviembre 2012 - 03:38

He modificado esta linea que tenia un error.

$res = mysql_query("select * from usuarios where telefono='".$_GET['telefono']."'")


  • 0

#5 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 01 noviembre 2012 - 03:50

He modificado esta linea que tenia un error.

$res = mysql_query("select * from usuarios where telefono='".$_GET['telefono']."'")


con eso se ha solucionado tu problema?
  • 0

#6 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 01 noviembre 2012 - 03:55

No se ha arreglado.
Mira te dejo este enlace donde hay un video ejemplo de autocompletar.Tendrias un ejemplo?
http://www.frogueros...input-dinamico/


  • 0

#7 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 01 noviembre 2012 - 05:36

No se ha arreglado.
Mira te dejo este enlace donde hay un video ejemplo de autocompletar.Tendrias un ejemplo?
http://www.frogueros...input-dinamico/



Trataré de darme tiempo el fin de semana para redactarte un tuto en mi blog
  • 0

#8 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 04 noviembre 2012 - 11:11

Poliburro has podido hacer el tutorial?
Un saludo
  • 0

#9 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 05 noviembre 2012 - 08:48

Poliburro has podido hacer el tutorial?
Un saludo


No amigo... mi fin de semana estuvo ocupadisimo... Veo que haces el window.onload = initFormEvents; podrías decirme si el camop teléfono recibe el cursor al cargar la página? has revisado que no marque error en la barra de estado del navegador?
  • 0

#10 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 05 noviembre 2012 - 09:11

Hola poliburro, no me marca nigún error!
  • 0

#11 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 05 noviembre 2012 - 09:22

Hola poliburro, no me marca nigún error!


modifica la función de esta manera y refresca la página. ME dices si aparece el alert
[java]

function initFormEvents() {
document.getElementById('telefono').onblur = getClientData;
document.getElementById('telefono').focus();
alert("El formulario ha sido inicializado.");

}

[/java]
  • 0

#12 jorgeu

jorgeu

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 179 mensajes
  • LocationMaracaibo

Escrito 05 noviembre 2012 - 09:53

acá pensando por qué no usar jQuery. Mucho más predecible y documentado que el método que usas  (y)
  • 0

#13 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 05 noviembre 2012 - 10:04

Hola, como lo hariamos?
  • 0

#14 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 05 noviembre 2012 - 10:35

[html5]modifica la función de esta manera y refresca la página. ME dices si aparece el alert
Código JAVA



function initFormEvents() {

document.getElementById('telefono').onblur = getClientData;

document.getElementById('telefono').focus();

alert("El formulario ha sido inicializado.");



}[/html5]
Poliburrro, he modificado y al refrescar me da el alert("El formulario ha sido inicializado.");
  • 0

#15 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 05 noviembre 2012 - 11:11

ok eso nos indica que se está ejecutando la inicialización... ahora vamos a eliminar esa bandera y colocar una nueva...

en la función getclientdata coloca después de la siguiente línea

if(telefono.length==9 && telefono!=currenttelefono){

alert (telefono);

y cuéntanos si despúes de capturar el teléfono te muestra algo
  • 0

#16 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 05 noviembre 2012 - 11:40

Ok, me da un alert con el nº ingresado.
Tambien te pongo la petición de red.
Luego lo he puesto aquí y:

Archivos adjuntos


  • 0

#17 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 06 noviembre 2012 - 11:15

Poliburro has visto lo que te puse ayer? y has podido hacer algo del tutorial?
Un saludo


EDITO: El Firebug me da error: ReferenceError: sack is not defined var ajax = new sack();

  • 0

#18 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 21 noviembre 2012 - 05:34

Hola Poliburro, quería saber si ha podido hacer al final el tutorial:

Re: Ajax no hace la llamada a php
« Respuesta #5 en: 01 de Noviembre de 2012, 15:55:57 »
Citar
No se ha arreglado.
Mira te dejo este enlace donde hay un video ejemplo de autocompletar.Tendrias un ejemplo?

http://www.frogueros...input-dinamico/

Un saludo
  • 0

#19 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 22 noviembre 2012 - 10:07

Hola Poliburro, quería saber si ha podido hacer al final el tutorial:

Re: Ajax no hace la llamada a php
« Respuesta #5 en: 01 de Noviembre de 2012, 15:55:57 »
Citar
No se ha arreglado.
Mira te dejo este enlace donde hay un video ejemplo de autocompletar.Tendrias un ejemplo?

http://www.frogueros...input-dinamico/

Un saludo



Saludos amigo... no he conseguido el tiempo pero este fin des semana lo hago... lo anuncaré aquí el lunes.... saludos
  • 0

#20 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 22 noviembre 2012 - 10:37

Gracias. :wink:
  • 0




IP.Board spam blocked by CleanTalk.