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条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题