如何确定请求是否在CodeIgniter中请求JSON


How to determine whether the request is asking for JSON in CodeIgniter?

可以在CodeIgniter中确定请求是否使用Ajax。CodeIgniter是否有任何方法,类似于Laravel的Request::wantsJson(),以确定请求是否要求JSON?

如果有一个application/json内容类型头就像"application/json内容类型"然后你只需要得到标题像这样,

$content_type = $this->input->get_request_header('Content-Type', TRUE);

然后根据$content_type的值制定一个条件响应。

哟。