EventSource的响应具有MIME类型(" text / html"),而不是" text / event-stream"。中止连接。 - Codeigniter

时间:2018-03-29 08:22:33

标签: php codeigniter server-sent-events

我在实施SSE时遇到错误。

错误: EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection. - Codeigniter

您可以在下面找到代码:

if(typeof(EventSource) !== "undefined") {   
    var path = "<?php echo base_url()?>lawyer/consultation/video_calling/<?php echo $client_user_id ?>";
    var source = new EventSource(path);
    source.onmessage = function(event) {
        var img_url     = '<?php echo base_url() ?>assets/images/main-logo.png';
        var resp        = JSON.parse(event.data);
        var id          = resp.id;
        var sender_id   = resp.sender_id;
        var receiver_id = resp.receiver_id;
        var session_id  = resp.session_id;
        var token       = resp.token;
        var client_receiver_id = <?php echo $client_user_id ?>;

        if(client_receiver_id == receiver_id){ 
            // alert('fgdgdg');
            spawnNotification('Somebody calling you!', ''+img_url+'', 'LawOn says');
            //document.getElementById("result").innerHTML += event.data + "<br>";
        }
    };
} else {
        document.getElementById("result").innerHTML = "SSE not Supported";
}

0 个答案:

没有答案