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

Problemas con ajax en servidor

Estas en el tema de Problemas con ajax en servidor en el foro de Frameworks JS en Foros del Web. Buenas, mi problema es el siguiente he hecho un pequeño sistema que permite ver, agregar y actualizar registros por medio de ajax usando php como ...
  #1 (permalink)  
Antiguo 13/07/2010, 08:16
 
Fecha de Ingreso: julio-2010
Mensajes: 7
Antigüedad: 13 años, 9 meses
Puntos: 0
Problemas con ajax en servidor

Buenas, mi problema es el siguiente he hecho un pequeño sistema que permite ver, agregar y actualizar registros por medio de ajax usando php como lenguaje servidor, en modo local funciona perfectamente, pero cuando subo el sistema en el servidor remoto, al pedir los datos de los registros via ajax el servidor no me manda nada, a que se debe esta falla y como la puedo resolver???
  #2 (permalink)  
Antiguo 14/07/2010, 17:37
Avatar de Potro  
Fecha de Ingreso: abril-2001
Mensajes: 2.249
Antigüedad: 23 años
Puntos: 39
Respuesta: Problemas con ajax en servidor

los datos los mandas a llamar de una db... si es asi verifica tu conexion..

Seria bueno que pongas algo de codigo...
__________________
Paginación en FLASH,

http://www.forosdelweb.com/f62/pagin...o-aqui-540241/
  #3 (permalink)  
Antiguo 16/07/2010, 15:42
Avatar de conetsol  
Fecha de Ingreso: mayo-2004
Mensajes: 60
Antigüedad: 20 años
Puntos: 0
Respuesta: Problemas con ajax en servidor

Hola muchas gracias por la respuesta sería algo asi?


Código HTML:
<!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>
<script>

function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}


function FAjax(url,capa,valores){
    var ajax=creaAjax();

	var newContent = ajax.responseText;
  	var mainTarget = document.getElementById(capa);



    ajax.open ('POST', url, true);
    ajax.onreadystatechange = function() {
        
	if (ajax.readyState==1) {
		capaContenedora.innerHTML="Cargando.......";
     
	 }else if (ajax.readyState==4){
           if(ajax.status==200){
           		document.getElementById(capa).innerHTML=ajax.responseText;
           }else if(ajax.status==404){
	           mainTarget.innerHTML = "La direccion no existe";
           } else{
				try { // Esto funciona perfecto con los navegadores reales
						mainTarget.innerHTML = newContent;
				} catch (e) { // Solución para IExplorer
						mainTarget.innerHTML = ''; // Eliminar contenido original
						var wrapDiv = document.createElement('capaContenedora'); // Crear nuevo elemento
						wrapDiv.innerHTML = newContent; // Asignar respuesta al nuevo elemento
						mainTarget.appendChild(wrapDiv); // Insertar nuevo elemento
					}
            }
     }
     
				
		
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(valores);
	 }

} 


</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post"  action="#"> <input name="" type="button" value="Button" onclick="FAjax('ajax2.php','capaContenedora','campo1=1');"  />

</form>
<div id="capaContenedora">

div
</div>
</body> 

Mil gracias!!!
  #4 (permalink)  
Antiguo 19/07/2010, 16:23
Avatar de Potro  
Fecha de Ingreso: abril-2001
Mensajes: 2.249
Antigüedad: 23 años
Puntos: 39
Respuesta: Problemas con ajax en servidor

Veo algunas inconsistencias en tu codigo..


Aqui debes de cambiar las lineas..

capaContenedora.innerHTML="Cargando.......";

document.getElementById(capa).innerHTML=ajax.respo nseText;


por

mainTarget.innerHTML="Cargando.......";

mainTarget.innerHTML=ajax.responseText;


Veo que tienes muchas validaciones tambien despues de que te contesta el ajax..
¨

Podrias quitar algunas...
__________________
Paginación en FLASH,

http://www.forosdelweb.com/f62/pagin...o-aqui-540241/
  #5 (permalink)  
Antiguo 19/07/2010, 16:28
Avatar de Potro  
Fecha de Ingreso: abril-2001
Mensajes: 2.249
Antigüedad: 23 años
Puntos: 39
Respuesta: Problemas con ajax en servidor

Si te sirve te dejo tu ejemplo con un ajax mas limpio..

**************************************


Código Javascript:
Ver original
  1. var peticion = false;
  2. var  testPasado = false;
  3. try {
  4. peticion = new XMLHttpRequest();
  5. } catch (trymicrosoft) {
  6. try {
  7. peticion = new ActiveXObject("Msxml2.XMLHTTP");
  8. } catch (othermicrosoft) {
  9. try {
  10. peticion = new ActiveXObject("Microsoft.XMLHTTP");
  11. } catch (failed) {
  12. peticion = false;
  13. }
  14. }
  15. }
  16. if (!peticion)
  17. alert("ERROR AL INICIALIZAR!");
  18.  
  19. function FAjax(url,capa,valores) {
  20.  
  21.     var element =  document.getElementById(capa);
  22.  
  23.     fragment_url = url+"?"+valores;
  24.    
  25.     element.innerHTML = 'Cargando...';
  26.     peticion.open("GET", fragment_url);
  27.     peticion.onreadystatechange = function() {
  28.         if (peticion.readyState == 4) {
  29.             element.innerHTML = peticion.responseText;
  30.         }
  31.     }
  32.     peticion.send(null);
  33.  
  34. }


Este setia otro ejemplo de cargar tu div....


NOTA: Ve que los datos los envio por GET ojo...


Saludos y suerte...
__________________
Paginación en FLASH,

http://www.forosdelweb.com/f62/pagin...o-aqui-540241/

Etiquetas: ajax, php
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 20:29.