dtjo51649 2012-01-02 03:40
浏览 143
已采纳

使用Chrome:Uncaught SyntaxError:意外的令牌<

I am getting this error Uncaught SyntaxError: Unexpected token < from chrome but everything works fine with FireFox. I have found many similar posts but no solution.

So I am wondering if there is a way of sending a second page to the browser after it has been build, with it's own header. The idea came, when I saw that Firefox places, what I echo in the function below, after the html closing tag , versus Chrome places it before the closing tag.

Basically, I like to send in this order:

header('Content-Type: text/html; charset= utf-8');
<html></html>

header('Content-Type: text/javascript; charset= utf-8'); 
<script></script>

This is my php script, I would like to uncomment the header code and send it independently from the html page.

public static function jsShow($html)
{
    //header('Content-Type: text/javascript; charset= utf-8');
    echo "
        <script type=\"text/javascript\">
        var e = document.getElementById('message');
        e.innerHTML = $html ;
        e.style.display = 'block';
        </script>";
}

This is what the page looks like in Firefox, and this works:

</body>
</html>

<script type="text/javascript">
var e = document.getElementById('message');
e.innerHTML = <ul style="list-style: none; margin: 0; padding: 0;">
<li style="background-color: #0000FF; margin: 0;"><img src="/asset/icon/info.gif" alt="Info: " /> working</li>
<li style="background-color: #008000; margin: 0;"><img src="/asset/icon/success.gif" alt="Success: " /> Got it</li>
</ul>
 ;
e.style.display = 'block';

</script>

I thought that I can maybe use ob_start() & ob_end_flush(), but you can't control headers with that only content.

  • 写回答

2条回答 默认 最新

  • dongqi9125 2012-01-02 03:42
    关注

    ...

            e.innerHTML = " . json_encode($html) . " ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集