javascript - 无法 .load() 包含类实例的 PHP 页面

标签 javascript php jquery oop

我正在制作一个交互式菜单,它使用 jQuery .load() 函数加载页面。

interactive menu

第一个按钮(显示带有视频的主提要)加载仅包含 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/

相关文章:

javascript - Firefox 中未定义图像 ID

javascript - 使用 javascript 将 css 系统颜色转换为十六进制?

php - MYSQL - 加入或子查询问题

PHP 从 SVG 文件中获取 svg 标签,并在 DIV 中以 HTML 显示

php - Laravel 队列错误 'Illuminate\Http\UploadedFile' 的序列化是不允许的

javascript - 如何在 jQuery 日期选择器的输入中制作自定义日期显示文本?

javascript - 使用 CSS 类禁用 Select

javascript - 有没有办法将 CSS 转换应用于在 mousemove 上进行 CSS 转换的元素内的元素?

javascript - 为什么 Rxjs publishReplay(1).refCount() 不重播?

javascript - 在 JavaScript 中将文本时间值转换为有效的日期格式