如何在php(或codeigniter)中区分ajax调用和浏览器请求?

dqi*_*qiu 5 php ajax jquery codeigniter

有没有办法区分ajax调用和PHP中的普通浏览器请求(或codeigniter是具体的)?

这是我的jquery ajax调用:

$(document).ready(function() {
    $('#container').load('http://localhost/index.php/customer/'); 
});
Run Code Online (Sandbox Code Playgroud)

这是codeigniter中客户控制器的索引方法:

public function index() {
    //if (call == 'ajax request') 
    //  do this if it's an ajax request;
    //else
    //  do that if user directly type the link in the address bar;
    $this->load->view('customer/listview');
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.谢谢.

Vam*_*a B 6

CodeIgniter方式..

$this->input->is_ajax_request()
Run Code Online (Sandbox Code Playgroud)