How to return the correct content-type for JSON in CakePHP?

前端 未结 5 590
别那么骄傲
别那么骄傲 2021-02-04 13:24

I\'m trying to set the content-type header for a JSON response accessed with an AJAX GET request. I\'ve followed tutorials on blogs and the bakery but I always receive \'text/ht

5条回答
  •  耶瑟儿~
    2021-02-04 14:05

    I've also just had this problem, and solved it by using:

    $this->RequestHandler->respondAs('text/x-json');
    

    Also make sure that "debug" in your config file is set to less than 2 otherwise the header will not be set.

提交回复
热议问题