我對所有的ajax調用都使用預定義的響應格式。Codeigniter CSRF響應格式
如果請求success
那麼服務器會迴應:
{"status":true,"data":{"name":"person","age":2}}
請注意data
是沒有必要的。
,如果再請求失敗,我會得到
{"status":false,"reason":"You are not authorised."}
所以每次響應有status
場,如果狀態是FALSE
則會有reason
場。
的問題是,現在我能夠CSRF
保護笨,如果令牌到期/失敗,系統會輸出
The action you have requested is not allowed.
這是HTML內容。
是否有可能延長安全類,因此,如果該請求是通過Ajax那麼它會保持json_encoded其他格式使用HTML格式。(我不想修改核心)
感謝。
也許它有幫助http://codeigniter.com/forums/viewthread/182631/P15/#997252 – aykut