weixin_33721427 2011-03-21 17:52 采纳率: 0%
浏览 25

在ZEND中处理JSONP调用

couldn't find an answer via search (or google) so i'll ask it myself. is it possible to handle JSONP calls to the zend framework?

only found this page:

http://framework.zend.com/wiki/display/ZFPROP/Zend_Json_Server+-+Lode+Blomme

but i'm not sure if it is already implemented!?

thx

  • 写回答

2条回答 默认 最新

  • weixin_33724046 2011-03-21 18:29
    关注

    JSONP is just a JSON response that is wrapped in a specified callback function that is executed on the client.

    Zend_Json_Server is only for JSON-RPC at the moment. The link you found is an archived (unimplemented) proposal to add JSONP support.

    The good news is that you don't need any sort of framework to support JSONP. Assuming $response is the data you wish to return to the user, and $callback contains the sanitized callback:

    echo $callback, '(', json_encode($response), ');';
    

    Tada, you've JSONP'd.

    Please take care to read the document I linked about sanitizing the callback. Failure to sanitize the callback may result in an exploitable condition.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站