我想包含每个加载的绝对路径,因为我已经重写了url并且想要确保populateResults.php
加载
$(document).ready(function() {
$("#results").load("functions/populateResults.php"); //initial page number to load
$(".pagination").bootpag({
total: <?php echo $pages; ?>,
page: 1,
maxVisible: 5
}).on("page", function(e, num){
e.preventDefault();
window.scrollTo(0, 0);
$("#results").prepend('<div class="loading-indication"><img src="/content/ajax-loader.gif" /> Please wait... Loading New Courses...</div>');
$("#results").load("functions/populateResults.php", {'page':num});
});
});
</script>
我不确定并且不认为做/ functions / populateResult会起作用。
更新
<?php $root_url = $_SERVER['HTTP_HOST']; ?>
<script>
var root_url = '<?= $root_url ?>';
$(document).ready(function() {
$("#results").load(root_url + "/functions/populateResults.php"); //initial page number to load
$(".pagination").bootpag({
total: <?php echo $pages; ?>,
page: 1,
maxVisible: 5
}).on("page", function(e, num){
e.preventDefault();
window.scrollTo(0, 0);
$("#results").prepend('<div class="loading-indication"><img src="/content/ajax-loader.gif" /> Please wait... Loading New Courses...</div>');
$("#results").load(root_url + "/functions/populateResults.php", {'page':num});
});
});
</script>
答案 0 :(得分:1)
这就是我要做的:使用PHP获取根URL,将其设置为变量并将其发送给JS,以便在您希望的地方使用它。
<?php
$base_url = $_SERVER['HTTP_HOST'];
?>
<script>
var base_url = '<?= $base_url ?>';
$(document).ready(function () {
$("#results").load(base_url + "/functions/populateResults.php");
//.. your other code..
});
</script>