Wednesday, December 1, 2010

Handling Redirect Issue in Ajax Call

function ajaxCall(){
var formData = getLibImgCartFormElements();
var url = "/myapp/test.jsp";
var params = "";

new Ajax.Request(
url,
{
method: 'post',
parameters: params,
onSuccess: function(response) {
if(isLoginRedirect(response)){
return;
}
$('yourDivName').innerHTML = contents;
},
onFailure: function(response) {
window.location = window.location.href;
}
}
);
}

function isLoginRedirect(response){
var contents = response.responseText;
if(response.status == 0 || contents == null || contents == '' || isLoginFormContents(contents)){
window.location = window.location.href;
return true;
}else{
return false;
}
}

function isLoginFormContents(contents){
var flag = false;
/*
* if((contents != null) && (contents.indexOf("") > 0)){ return true; }else{ return false; }
*/
return flag;
}

No comments:

Post a Comment