我的Codeigniter文件说
$CI->output->set_header("Access-Control-Allow-Origin: *"); $CI->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); $CI->output->set_status_header(200); $CI->output->set_content_type('application/json'); echo json_encode(array("city" => "dhaka"));
但是我得到的http响应是:
Request URL:http://localhost/index.php/location/city Request Method:POST Status Code:200 OK Connection:Keep-Alive Content-Length:16 Content-Type:text/html Date:Sun, 22 Jul 2012 10:27:32 GMT Keep-Alive:timeout=5, max=100 Server:Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 X-Powered-By:PHP/5.3.6
Access-Control-Allow-Origin即使包含,响应中仍缺少标题Access-Control-Expose-Headers: Access-Control-Allow- Origin。我有关此标头的信息来源来自Mozilla开发人员网站
Access-Control-Allow-Origin
Access-Control-Expose-Headers: Access-Control-Allow- Origin
事实证明,仅当我通过PHP语法header()而不是codeigniter语法设置标头时,它才对我有用$CI->output->set_header()。真伤心
header()
$CI->output->set_header()