dongxifu5009 2016-11-09 22:50
浏览 49
已采纳

从响应中删除标头值

I have a laravel system and I am storing one of my response in a particular file like this :

$objFile = new Filesystem();
        $path = "files/FileName.php";
        $string = $this->getSlides();
        if ($objFile->exists($path))
        {
            $objFile->put($path,"",$lock = false);
            $objFile->put($path,$string,$lock = false);
            $objFile->getRequire($path);
        }
        else
            return getcwd() . "
";

Now i get the contents using the following lines:

$objFile = new Filesystem();
        $path = "files/FileName.php";

        if ($objFile->exists($path))
        {
            return Response::json([$objFile->getRequire($path)],200);
        }
        else
            return getcwd() . "
";

Now what's happening is that when I store the file on the server it adds some header like :

HTTP/1.0 200 OK
Cache-Control: no-cache
Content-Type:  application/json
Date: Thu, 10 Nov 2016 05:38:08 GMT

followed by my stored file , so when I call the file on my frontend , I get the following error :

SyntaxError: Unexpected token H in JSON at position 0(…)

of course it expects from me a json value however i m giving it something that doesn't start like 1. Any idea how i can remove that on php level?

展开全部

  • 写回答

2条回答 默认 最新

  • douweiluo0600 2016-11-10 00:28
    关注

    Sorry I made a bit of blunder while retrieving the result: In the getSlides method i was using :

    return Response::json([
          'Data' => $final_array
      ],200);
    

    Now i replaced it with :

    $final_array2 = array(
          'Data' => $final_array
          );
      return json_encode($final_array2);
    

    Sorry because i didn't put this code and hence no one could have got any idea

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 有人帮看看这个问题的嘛
  • ¥15 STM32悬赏求解答,ai不要来解答
  • ¥15 Mysql 一张表同时多人查询和插入怎么防止死锁
  • ¥20 centos6.7 安装libevent库.总是报错,如何解决?
  • ¥15 电脑买回,学校的有线网络总掉。
  • ¥20 关于普洛菲斯触摸屏与AB连接地址问题
  • ¥15 syri可视化不显示插入缺失
  • ¥30 运行软件卡死查看系统日志分析不出来
  • ¥15 C语言代码改正特征选择算法设计,贝叶斯决策,,设计分类器,远程操作代码修正一下
  • ¥15 String 类valuve指向的问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部