【问题标题】:Laravel pusher error: JSON returned from webapp was invalid, yet status code was 200Laravel pusher 错误:从 webapp 返回的 JSON 无效,但状态码为 200
【发布时间】:2016-10-24 08:45:00
【问题描述】:

我在 laravel 5.2 上工作,我添加了 vinkla/laravel-pusher 在我的网站上做实时聊天应用程序,但我遇到了这个问题: “从 webapp 返回的 JSON 无效,但状态码为 200。” 这是我的控制器:

public function authMessageChat(Request $req)
    {

        $channelName = e($req->input('channel_name'));
        $socketId = e($req->input('socket_id'));
        $auth = $this->pusher->presence_auth($channelName, $socketId, auth()->user()->id);
         return response($auth);

    }

这是我的脚本:

var pusher = new Pusher('{{env("PUSHER_KEY")}}', {
    authEndpoint: '../auth',
    auth: {
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        params: {
            id: currentUser.id
        }
    }
    });
    var channel = pusher.subscribe('{{$chatChannel}}');
    channel.bind('pusher:subscription_error', function(PusherError){
            console.log('PusherError' + PusherError);
        });
        channel.bind('new-message', function(data) {
        console.log(data.sender);
)};

推杆错误:

【问题讨论】:

    标签: php json laravel-5.2 pusher


    【解决方案1】:

    @chrissou 谢谢你的回答..

    您的答案是正确的,我们可以通过其他方式实施解决方案。 只需转到您的 .env 文件并制作:

    APP_DEBUG=false
    

    而不是

    APP_DEBUG=true
    

    谢谢

    【讨论】:

      【解决方案2】:

      看起来您的应用正在返回调试栏 html 作为 json 响应的一部分。

      假设您使用的是 barryvdh/laravel-debugbar,根据the documentation,您可以在运行时关闭调试栏:

      Config::set('laravel-debugbar::config.enabled', false);
      

      我假设您需要在发送响应之前在您用于身份验证端点的控制器方法/路由中添加它(即,您从中调用socket_auth 方法的那个)

      【讨论】:

        猜你喜欢
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 2012-03-06
        • 2020-04-12
        • 2013-02-18
        • 1970-01-01
        • 2017-07-12
        • 1970-01-01
        相关资源
        最近更新 更多