2012-11-20 32 views
0

如果我的web應用程序收到由於不活動而具有陳舊cookie的用戶的JSON調用,我的webapp框架將返回303嘗試將瀏覽器重定向到登錄頁面。

我想在回調函數中捕獲它,但在遇到重定向時它似乎沒有執行。我如何處理JQuery Ajax調用中的重定向?如果用戶在註銷後嘗試進行JSON調用,我只想刷新頁面,因爲默認情況下會將用戶重定向到登錄頁面。

+0

可能的解決方法可以在這裏找到=> http://stackoverflow.com/questions/2927044/redirect-on-ajax-jquery -call – anderssonola

+0

@esailija你回覆了我的評論後刪除了你的回答? – anderssonola

+0

請參閱此問題:http://stackoverflow.com/questions/7867021/mootools-how-to-get-redirected-if-ajax-request-returns-redirect-code – Rajnish

回答

0

@ esailija的解決方案工作,使他們不必已將其刪除:

function myfunc(){ 
    $.getJSON('serverJSONCall',function(data){ 
     if(data.success){ 
      // do something interesting 
    }).error(function() { 
     location.reload(); 
    }); 
}