我正在使用 ajax 加载一个基于屏幕分辨率显示内容的 php 脚本。该脚本运行良好,但 ajax 调用的 url 也会在脚本中稍后调用——它包含所有处理信息。因此,结果是所有内容都通过 jquery 加载,然后用 php 复制。例子:
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: 'functions/maxresults.php',
type: 'GET',
data: {h: screen.height, w: screen.width}
}).done(function ( data ) {
alert("I am working!");
document.getElementById("container").innerHTML=data;
});
});
</script>
再往下
<?php
include_once("functions/maxresults.php");
?>
<?php
require_once("databasefunctions.php");
?>
<div id="container">
<div id="movieinfo">
<?php include("sidebar.php");?>
<?php
// get the function
include_once ('function.php');
if($_GET['page'])
$page = $_GET['page'];
else
$page = 0;
$maxresults = -1;
if(($_GET['w']) && ($_GET['h'])) {
$w = $_GET['w'];
$h = $_GET['h'];
}
if ($w == 1920) {
$maxresults = 24;
} else if ($w == 1600) {
$maxresults = 21;
} else if ($w == 1440){
$maxresults = 14;
} else if ($w == 1366) {
$maxresults = 21;
} else if ($w == 1024) {
$maxresults = 8;
} else
$maxresults = 6;
echo $maxresults;
$currentpage = $page;
$page = $page*$maxresults;
$numpages = QuickQuery("SELECT COUNT(id) FROM movies WHERE visible=1");
$numpages = mysql_result($numpages, 0);
$numpages = $numpages/$maxresults-1;
$result = GetMoviesByRangeID($page, $maxresults);//Show <maxresults> pages at a time
DisplayResults($result);
?>
</div>
</div>
我无法删除 php 包含或脚本根本无法工作。在 jquery 中创建一个 include_once 会起作用吗?如果是这样,我该如何编码?