Foros del Web » Programando para Internet » Javascript »

Problema con petición AJAX en Javascript

Estas en el tema de Problema con petición AJAX en Javascript en el foro de Javascript en Foros del Web. Hola a todos, Estoy teniendo problemas al hacer una petición AJAX con Javascript en IE11. Pongo el código a continuación: Código: function ajaxFunction(url, params, ret_fun_ok, ...
  #1 (permalink)  
Antiguo 24/02/2015, 08:43
 
Fecha de Ingreso: julio-2010
Mensajes: 298
Antigüedad: 13 años, 9 meses
Puntos: 8
Problema con petición AJAX en Javascript

Hola a todos,
Estoy teniendo problemas al hacer una petición AJAX con Javascript en IE11. Pongo el código a continuación:
Código:
function ajaxFunction(url, params, ret_fun_ok, ret_fun_nook)
{
   var xmlHttp = createXMLHttp(); 
   xmlHttp.open("POST", url, true);
   //Send the proper header information along with the request
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

   xmlHttp.onreadystatechange = function ext2(){
      if ( xmlHttp.readyState == 4 ) {
         if ( xmlHttp.status == 200 ) {
            ret_fun_ok(xmlHttp.responseText);
         } else {
            ret_fun_nook(xmlHttp.status);
         }
      }
   };
   xmlHttp.send(params);
}
function createXMLHttp() 
{
   if (typeof XMLHttpRequest != 'undefined')
      return new XMLHttpRequest();
   else if (window.ActiveXObject) {
      var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp","MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.5.0"];
      for (var i = avers.length -1; i >= 0; i--) {
         try {
         httpObj = new ActiveXObject(avers[i]);
         return httpObj;
         } catch(e) {}
      }
   }
   throw new Error('XMLHttp (AJAX) not supported');
}
function ajaxOnTrue(result) {
   alert(result);
}
function ajaxOnFalse(status) {
   alert(status);// status = 0
}
ajaxFunction('https://www.myserverdomain.com/services/Request.ashx', "param1=value1&param2=value2", ajaxOnTrue, ajaxOnFalse);
Por lo que veo en el servidor, siempre devuelve un código 200, pero cuando llega la petición al PC del usuario final, mmuestra un "xmlHttp.status=0", alguien sabe a que se debe? Sólo me sucede en IE11.

Muchas gracias por la ayuda
  #2 (permalink)  
Antiguo 24/02/2015, 12:12
Colaborador
 
Fecha de Ingreso: septiembre-2013
Ubicación: España
Mensajes: 3.648
Antigüedad: 10 años, 7 meses
Puntos: 578
Respuesta: Problema con petición AJAX en Javascript

Puede ser por el tema de cross-domain. IE trabaja de forma distinta:

http://stackoverflow.com/questions/5...y-script-on-ie

Etiquetas: ajax, post, status
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 23:30.