我使用jQuery ajax和Codeigniter創建了一個應用程序。現在,當我的會話到期時,如果它是真的,我將它的$ this-> session-> userdata('user_data')設置爲空,我將它設置爲未授權的標題狀態401。並應返回正在返回的自定義數據。
這裏是我的代碼:
if(empty($this->session->userdata('user_data'))) {
if($this->input->is_ajax_request()){
$this->output
->set_content_type('application/json')
//set cutom output.
->set_output(json_encode(array('response_code' => 401, 'message' => 'unauthorized')))
->set_status_header('401');
}
else {
//redirect to login page
redirect('login/logout');
}
}
,你可以看到我設置的自定義輸出爲JSON。 我的Ajax請求是
$(document).ajaxError(function(e,xhr,o) {
// how can I fetch the contents from here?
});
var url = /*url for my controller */;
var params = /* objects to be passed */;
$.post(url, params).done(function(e){
console.log('success');
});
來源: 我發現頭中CI documentation output class
是的,我們對此深感抱歉,是我宣佈在全球範圍的。使用$(document).ajaxError(function(e,xhr,o){});請參閱我的編輯。 – loki9 2014-10-18 05:54:12
好的,你有什麼迴應?,使用**螢火蟲**看到阿賈克斯respose – Girish 2014-10-18 06:09:13