how to implement JsonP in cakephp 2.4

喜欢而已 提交于 2019-12-04 17:00:53

It should have worked fine with the older Cake version too, just as I've described in your other question ;)

Anyways, look at the code in /lib/Cake/View/JsonView.php or in the API documentation. You have to define a view var named _jsonp, which can be either a string specifying the name of the query variable that holds the callback function name, or true which means a default query variable with the name callback is being looked up.

So as jQuery uses a query variable name of callback by default, defining true for _jsonp should do it:

$this->set(array(
    'member' => $members,
    '_serialize' => array('member'),
    '_jsonp' => true
));

In case no query variable named callback could be found in the request URL (ie ?callback=whatever), you'd receive a regular JSON response instead.

See also

If that just don't work, try to change the value of $jsonpParam from "callback" to "jsoncallback" (in lib/Cake/View/JsonView.php). I had to do that for make it work, thats because the name of the variable in the jsonp request, is jsoncallback, this one contains the string of the callback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!