我正在制作一个交互式菜单,它使用 jQuery .load() 函数加载页面。
第一个按钮(显示带有视频的主提要)加载仅包含 Class 实例的文件 feed.php,然后调用方法:
<h3>Main feed</h3>
<?php
$videos = new Video();
$videos->getVideos();
?>
类Video()在包含的文件function.php中定义。
树:
index.php
—init.php (DB)
——functions.php
—header.php (Logo & Menu itself)
—content.php (#content divs)
——feed.php (Main feed)
当我刷新页面时,提要加载没有问题。 但是当我单击第一个按钮时,jQuery 尝试将 feed.php 加载到 #content 元素中,但失败了。
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
其他按钮工作正常。
这种做法错了吗?或者我只是错过了什么?
最佳答案
你需要使用
require_once 'link_to_php_file.php';
您可以在两个文件(无论您要使用多少个文件)中使用它,但该文件只会被包含一次。
来自官方 PHP
文档。
The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again.
访问require_once
了解更多信息。
希望这对其他人也有帮助。
关于javascript - 无法 .load() 包含类实例的 PHP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33067541/