我为我的所有 ajax 调用使用了预定义的响应格式。
如果请求是,success
那么服务器将响应:
{"status":true,"data":{"name":"person","age":2}}
请注意data
不是必需的。
如果请求失败,那么我会得到
{"status":false,"reason":"You are not authorised."}
所以每个响应都有一个status
字段,如果状态是FALSE
那么就会有reason
字段。
问题是现在我CSRF
在 Codeigniter 中启用了保护,如果令牌过期/失败,系统输出
The action you have requested is not allowed.
这是 HTML 内容。
是否可以扩展安全类,这样如果请求是通过 Ajax 的,那么它将保持 json_encoded 格式,否则使用 html 格式。(我不想修改核心)
谢谢。