我正在尝试为我正在构建的 ModX Revo 网站构建自己的预取器。
我现在Syntax Error
上<script type="text/javascript">
线了
我怎样才能让它正常工作?
我将它包含在我的页面/模板中<script type="text/javascript" src="/prefetcher.php"></script>
这是代码:
<?php
header('Content-Type: text/javascript');
require_once($_SERVER['DOCUMENT_ROOT'] . '/assets/php/m.inc.php');
//if(!@$_SESSION['AlreadyPrefetched']){
$sql = "Select `pagetitle`, `longTitle`, `uri` From `modx_site_content`
Where `type` = 'document' And `published` = 1 AND
(`uri` <> 'portfolio/item' And `uri` <> 'error-page-401' And `uri` <> 'sitemap.xml' And `uri` <> 'error-page-404' And
`uri` <> 'error-page-other' And `uri` <> 'index')";
$qry = $modx->query($sql);
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$rCt = count($rows);
if($rCt > 0){
$_SESSION['AlreadyPrefetched'] = true;
echo '<script type="text/javascript">
$(window).on("load", function(){
alert("Prefetch Active");';
for($i = 0; $i < $rCt; ++$i){
echo ' $.ajax({ url:"/'. $rows[$i]['uri'] .'", cache:true, dataType:"text", success:function(){}, error:function(){} });';
}
echo ' });
</script>';
}
unset($rows);
//}
?>
观察 FireBug,对 prefetch.php 的请求以正确的内容类型返回...