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

前端 未结 5 542
别那么骄傲
别那么骄傲 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:03

    I am not sure (and, to be honest, I've never used CakePHP), but you may want to try to specify a second argument in the setContent method..

    replace this:

    $this->RequestHandler->setContent('json') 
    

    with this:

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

    see this file for an example..

提交回复
热议问题