企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Json & Jsonp 输出 我们通常会在前端用到JSON. 所以框架内置了两个简单的 JSON格式化输出函数 ## Json 该函数会更改 Content-Type 类型为 application/json; charset=utf-8 ~~~ <?php namespace Action; use HY\Action; class Index extends Action { public function Index(){ $arr = array(1,2,3); $this->json($arr); } } ~~~ +++ get:/ <<< success [1,2,3] +++ ## jsonp 可能新手不懂jsonp是什么意思. jsonp是提供给跨域访问使用的. 放A网站使用了ajax去获取 B网站的一个JSON数据 但两者是不同的域名 造成了 跨域危险. 所以AJax是不能直接通信的 所以只能采用JavaScript脚本的方法 使用函数去执行 格式化远程端的字符串JSON ~~~ <?php namespace Action; use HY\Action; class Index extends Action { public function Index(){ $arr = array(1,2,3); $this->jsonp($arr,'run'); } } ~~~ +++ get:/ <<< success run([1,2,3]); +++