Foros del Web » Programando para Internet » Javascript »

Internet Explorer v8 no realiza funcion a la primera

Estas en el tema de Internet Explorer v8 no realiza funcion a la primera en el foro de Javascript en Foros del Web. Hola todo mundo del Foros del Web, He aquie nuevamente trayendo dudas Estoy haciendo una pagina en la cual mando a llamar una funcion de ...
  #1 (permalink)  
Antiguo 08/08/2011, 12:13
Avatar de Huacho12  
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Internet Explorer v8 no realiza funcion a la primera

Hola todo mundo del Foros del Web,

He aquie nuevamente trayendo dudas

Estoy haciendo una pagina en la cual mando a llamar una funcion de enviar desde un archivo .js el cual claro esta lo defino en el

Código Javascript:
Ver original
  1. <script language="javascript" type="text/javascript" src="carpetaJS/js.js" ></script>

Este pagina la he probado en FireFox, Opera, Safari, Crome, los cuales al darle click al boton luego luego envia los datos para ser guardados. Lo extraño es que al probarla en Internet Explorer 8 no realiza la funcion a la primera, si no que se tiene que dar F5 para que agarre la funcion lo extraño tambien que no borra la información capturada !!!!

La funcion que uso esta echa con AJAX, se las dejo:


//Archivo js.js

Código Javascript:
Ver original
  1. var XMLHttpRequestObj = false;
  2.  
  3. /*if(window.XMLHttpRequest)
  4. {
  5.     XMLHttpRequestObj = new XMLHttpRequest();
  6.  
  7. }else if(window.ActiveXObject)
  8. {
  9.     XMLHttpRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
  10. }*/
  11.  
  12. if(typeof(XMLHttpRequest) != 'undefined')
  13. {
  14.     try
  15.     {
  16.          XMLHttpRequestObj = new  XMLHttpRequest();    
  17.     }catch(e){}
  18. }else
  19. {
  20.     try
  21.     {
  22.          XMLHttpRequestObj = new ActiveXObject('Microsoft.XMLHTTP');
  23.     }catch(e)
  24.     {
  25.          XMLHttpRequestObj = new ActiveXObject('Msxml2.XMLHTTP');
  26.     }
  27. }
  28.  
  29. function sendWithPOST(pagina, datos, obj)
  30. {
  31.     if(XMLHttpRequestObj)
  32.     {
  33.         var div = document.getElementById(obj);
  34.         XMLHttpRequestObj.open("POST",pagina,true);
  35.         XMLHttpRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  36.        
  37.         XMLHttpRequestObj.onreadystatechange = function(){
  38.             if(XMLHttpRequestObj.readyState == 4 && XMLHttpRequestObj.status == 200)
  39.             {
  40.                 div.innerHTML = XMLHttpRequestObj.responseText;
  41.             }else
  42.             {
  43.                 div.innerHTML = "Cargando....";
  44.             }
  45.         }
  46.        
  47.         XMLHttpRequestObj.send(datos);
  48.     }
  49. }
  50.  
  51. function enviar()
  52. {
  53.            var formulario = document.myform;
  54.            /*
  55.             //
  56.             //
  57.             //Todas las validaciones de la pagina
  58.             //
  59.             //
  60.             //
  61.           */
  62.              var informacion = "info1="+encodeURIComponent(formulario.txtUno);
  63.             sendWithPOST('guardaDatos.php', informacion , 'Contenedor');
  64. }

Y aqui el boton:

Código HTML:
Ver original
  1. <input type="button" name="btnSave" id="btnSave" value="Guardar" onclick="javascript:enviar();" />

Espero me puedan orientar en lo que estoy haciendo mal, ya que esta misma funcion la utilzo en otra pagina y no me ocasiona estos problemas.

Saludos y muchisimas gracias de antemano
__________________
Solo se... que no se nada!!! 0_o
  #2 (permalink)  
Antiguo 08/08/2011, 13:28
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Internet Explorer v8 no realiza funcion a la primera

prueba a asignar la función con la que creas el objeto a una variable dentro de la función sendWithPOST()
  #3 (permalink)  
Antiguo 08/08/2011, 14:01
Avatar de Huacho12  
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: Internet Explorer v8 no realiza funcion a la primera

Hola IsaBelm!!

Gracias por contestar,

A cual funcion te refieres??? a la de ................

Código Javascript:
Ver original
  1. function(){
  2.             if(XMLHttpRequestObj.readyState == 4 && XMLHttpRequestObj.status == 200)
  3.             {
  4.                 div.innerHTML = XMLHttpRequestObj.responseText;
  5.             }else
  6.             {
  7.                 div.innerHTML = "Cargando....";
  8.             }
  9.         }

o cual????

Perdon no me quedo muy claro tu comentario...


Saludos y nuevamente muchas gracias.
__________________
Solo se... que no se nada!!! 0_o
  #4 (permalink)  
Antiguo 08/08/2011, 14:18
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Internet Explorer v8 no realiza funcion a la primera

me refiero a esto
Cita:
function creaObj() {
var XMLHttpRequestObj = false;
.......

}
return XMLHttpRequestObj;
}

function sendWithPOST(pagina, datos, obj)
{
var XMLHttpRequestObj = creaObj();

var div = document.getElementById(obj);
.....
  #5 (permalink)  
Antiguo 08/08/2011, 14:31
Avatar de Huacho12  
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: Internet Explorer v8 no realiza funcion a la primera

Hola nuevamente IsaBelm,

Acabode hacer la modificacione que me comentaste pero sigue haciendo lo mismo!! no realiza el envio a la primera!!!


Código Javascript:
Ver original
  1. function creaObjt()
  2. {
  3. var XMLHttpRequestObj = false;
  4.  
  5. /*if(window.XMLHttpRequest)
  6. {
  7.     XMLHttpRequestObj = new XMLHttpRequest();
  8.  
  9. }else if(window.ActiveXObject)
  10. {
  11.     XMLHttpRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
  12. }*/
  13.  
  14. if(typeof(XMLHttpRequest) != 'undefined')
  15. {
  16.     try
  17.     {
  18.          XMLHttpRequestObj = new  XMLHttpRequest();    
  19.     }catch(e){}
  20. }else
  21. {
  22.     try
  23.     {
  24.          XMLHttpRequestObj = new ActiveXObject('Microsoft.XMLHTTP');
  25.     }catch(e)
  26.     {
  27.          XMLHttpRequestObj = new ActiveXObject('Msxml2.XMLHTTP');
  28.     }
  29. }
  30.  
  31. return XMLHttpRequestObj ;
  32. }

Cita:
function sendWithPOST(pagina, datos, obj)
{
var XMLHttpRequestObj = creaObjt();

var div = document.getElementById(obj);
.....
Saludos
__________________
Solo se... que no se nada!!! 0_o
  #6 (permalink)  
Antiguo 08/08/2011, 15:44
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Internet Explorer v8 no realiza funcion a la primera

no he logrado reproducir el problema que tienes. prueba con este código, a ver que alerta no levanta
Cita:
function creaObj(){
var obj = false;
obj = new XMLHttpRequest();
return obj;
}


function sendWithPOST(pagina, datos, obj) {
var div = document.getElementById(obj);
var XMLHttpRequestObj= creaObj();
XMLHttpRequestObj.open("POST", pagina, true);
XMLHttpRequestObj.onreadystatechange = function() {

alert('entró en sendWithPOST()');

if (XMLHttpRequestObj.readyState==4 && XMLHttpRequestObj.status==200){
div.innerHTML = XMLHttpRequestObj.responseText;
}

}

XMLHttpRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
XMLHttpRequestObj.send(datos);
return;
}


function enviar() {
var formulario = document.myform;
/*
//
//
//Todas las validaciones de la pagina
//
//
//
*/

var informacion = "info1="+encodeURIComponent(formulario.txtUno) ;
alert('entró en enviar()');
sendWithPOST('guardaDatos.php', informacion , 'Contenedor');
}
  #7 (permalink)  
Antiguo 09/08/2011, 08:25
Avatar de Huacho12  
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: Internet Explorer v8 no realiza funcion a la primera

Hola IsaBelM!!!

Ya he probado los cambios que me pusistes.

Muestra el Alert de que si entro a enviar() y posteriormente al de sendWithPost() pero este ultimo alert lo muestra tres veces!!!! y posteriormente envia la informacion para guardarla.....

Sera por el return que se tiene puesto???? en la funcion de sendWithPost()?????

Saludos y nuevamente gracias por tu valiosa ayuda!!!!
__________________
Solo se... que no se nada!!! 0_o
  #8 (permalink)  
Antiguo 09/08/2011, 13:34
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Internet Explorer v8 no realiza funcion a la primera

creo entender que ya funciona correctamente, no??

en realidad debería de alertar 4 veces no 3. si cambia esa alerta por
Cita:
alert(XMLHttpRequestObj.readyState)
verás en que estado está la petición. el orden en que te aparecerán será: 2, 3, 4, 1

Etiquetas: explorer, funcion, html, internet, js, primera, formulario, botones
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 06:28.