我有一个HTML页面需要使用jQuery AJAX函数向受CAS保护的(
Central Authentication Service)Web服务发出请求.我有以下代码:
$.ajax({
type: "GET",url: request,dataType: "json",complete: function(xmlHttp) {
console.log(xmlHttp);
alert(xmlHttp.status);
},success: handleRedirects
});
请求变量可以是CAS服务器(https://cas.mydomain.com/login?service=myServiceURL),也可以直接发送到服务(然后应该重定向回CAS以获取服务票证). Firebug显示正在进行请求,并返回302重定向.但是,$.ajax()函数不处理重定向.
我写了这个函数来解决这个问题:
var handleRedirects = function(data,textStatus) {
console.log(data,textStatus);
if (data.redirect) {
console.log("Calling a redirect: " + data.redirect);
$.get(data.redirect,handleRedirects);
} else {
//function that handles the actual data processing
gotResponse(data);
}
};
但是,即使这样,handleRedirects函数也永远不会被调用,并且xmlHttp.status总是返回0.它看起来也不像是通过cas.mydomain.com调用发送cookie. (有关类似问题,请参阅this question.)
这是AJAX调用没有处理重定向的问题,还是有更多的事情发生在这里而不是眼睛?