Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/02/2013, 11:17
Pimager
 
Fecha de Ingreso: julio-2010
Mensajes: 298
Antigüedad: 13 años, 9 meses
Puntos: 8
Error en petición AJAX a otro servidor

Hola a todos, tengo un problemilla, resulta que desde una página hago una llamada AJAX a un servicio alojado en otro servidor, y resulta que siempre me entra en la parte de "RESPONSE KO", cuando sé perfectamente que dicho servicio funciona perfectamente.
Alguien sabe a que se debe?
Les dejo el trozo de código que estoy usando en mi pa´gina:
Código:
function init() {
    ajaxFunction('http://myOtherDomain/MyService.ashx', "", OnOK, OnKO);
}
function OnOK() {
	alert("Ok");
}
function OnKO() {
	alert("Ko");
}
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.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);

    xmlHttp.onreadystatechange = function ext2() {
        if (xmlHttp.readyState == 4) {
            alert("xmlHttp.status = " + xmlHttp.status);
            if (xmlHttp.status == 200) {
                ret_fun_ok(xmlHttp.responseText);
            } else {
                ret_fun_nook();
            }
        }
    };

}
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');
}