【问题标题】:Bootstrap Cannot modify header informationBootstrap 无法修改标头信息
【发布时间】:2021-11-15 23:34:30
【问题描述】:

我尝试做一个通知系统,每次有人发布新帖子时都会播放声音。 我在 boostrap 4 工作 我已经通过在函数页面中插入 javascript 来改变方法,但是当我调用 javascript 函数时,我会以各种方式出现与之前相同的错误 我只发布所有代码的一部分,因为是维度 我调用的脚本是 play_sound 我像这样呼唤回声

echo '<script type="text/javascript">play_sound();</script>';

然后我得到了同样的错误

This is my error

警告:无法修改标头信息 - 标头已由第 208 行的 /home/nicetaxi/public_html/helpers/Functions.php 中的 /home/nicetaxi/public_html/helpers/Functions.php:1 发送的标头

这是我的错误所在

function redirect_to_page($path = null)
{
header("location:" . SITE_ADDR . $path);
}

How can i solve this error

This is the functions page

<script type="text/javascript">
function play_sound() {
    var audioElement = document.createElement('audio');
    audioElement.setAttribute('src', 'https://www.nicetaxi.eu/download/notifications.mp3');
    audioElement.setAttribute('autoplay', 'autoplay');
audioElement.setAttribute('muted', 'muted');
    audioElement.load();
    audioElement.play();
}
</script>
<?php

【问题讨论】:

    标签: javascript php bootstrap-4


    【解决方案1】:

    避免header()之前的echo语句,触发“Header has been sent out error”。 如果强制使用回显

    改用 javascript 重定向 window.location.href = '网址; //会带你到url。

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多