PHP和$(文档).ready()冲突

时间:2014-03-13 23:23:39

标签: php jquery

我从工作中继承了一个网站,内置的php代码保持$(document).ready()函数不在代码中运行。当我删除它时,我点击了jquery代码,但我需要PHP代码来运行该网站。

PHP

<?php if(strstr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'WDG_SiteValidator') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'W3C-checklink') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'Web-Sniffer') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'FeedValidator') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'Poodle predictor') ||
     strstr($_SERVER['HTTP_USER_AGENT'], 'Leknor.com gzip tester')) {
$mime = 'application/xhtml+xml';
} else {
if(stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) {
    if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",       $_SERVER['HTTP_ACCEPT'], $matches)) {
        $xhtml_q = $matches[1];
        if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i", $_SERVER['HTTP_ACCEPT'], $matches)) {
            $html_q = $matches[1];
            if((float)$xhtml_q >= (float)$html_q) {
                $mime = 'application/xhtml+xml';
            }
        }
    } else {
        $mime = 'application/xhtml+xml';
    }
} else {
    $mime = 'text/html';
}
}
header('Content-Type: ' . $mime . ';charset=utf-8');
header('Vary: Accept'); ?>

它后面的行是:     

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="keywords" content="keywords"/>

<script type='text/javascript' src = 'jquery-1.11.0.js'> </script>
<script type='text/javascript' src = 'jquery.fancybox.js'> </script>
<link rel='stylesheet' type='text/css' href='jquery.fancybox.css' />
<link rel='stylesheet' type='text/css' href='bicep2default.css'/>

<script type='text/javascript'>
    $(document).ready(function() {
        console.log('doc is ready')
    });
</script>

<script type='text/javascript'>

var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-3725824-1']);
    _gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

</head>

我从来没有看到&#39; doc准备就绪&#39;使用脚本中的php代码。

我该怎么办? 谢谢!

1 个答案:

答案 0 :(得分:0)

删除最后两行php header()行,然后在模板中添加<html> ... </html>