【发布时间】:2016-10-10 18:52:37
【问题描述】:
有人在我错的地方提供帮助! Ajax 返回正确的信息。它还显示在“成功”包含页面上,所有数据都在“警报(html)”中。回声 $idName;并回显 $path;在载体页上打印正确的信息(代码在哪里)。页面中没有小食。 Require 方法不会阻塞页面。问题是 div include 仍然是空的!谢谢。
<div id="include">
<?php
if (isset($_POST['idName1'])) {
$idName = $_POST['idName1'];
$query = mysqli_query($mysqli, "SELECT in_path FROM strani WHERE id_name='$idName '");
$row_path = mysqli_fetch_array($query);
$path = $row_path['in_path'];
require($path); /*Also tried: require(dirname(__FILE__)."/".$path); all the same!*/
}
?>
</div>
因为我想进一步解释,它不会像评论一样通过,我声明编辑问题。附上文件结构和目录,以及为缩短程序而更改的代码,以显示错误。预测的场景如下:授权的用户登录后,将打开 main-page.php,其中包含允许编辑的可选表单菜单。该页面立即包含“form-carrier.php”,其中包含一些-data.php。一旦通过anchor标签,他会选择合适的表格,这个表格应该包含在合适的div中,“id=include”。
Page structure:
main-page.php > It includes file: require(form-carrier.php) which iclude: require(form.php); and: require(some-data.php);
Dir structure:
secured-dir (It contains files: login.php; error.php; error-log)
styles-dir
js-dir
includes-dir (It contains files: functions.php; db-conn-conf.php; process-login-logout.php; session-class.php; error-log)
forms-dir (It contains files: form-carrier.php; some-data-php; error_log)
forms-byclass1-subdir (It contains files: form-some-name.php; error_log)
forms-byclass2-subdir (It contains files: form-some-name.php; error_log)
..... other sub dirs....
working-dir It contains files: (main-page.php; error_log)
通过键入指定路径进行测试,发现在require(“forms-byclass1-subdir/form-some-name.php”);以及“../forms-dir/forms-byclass1-subdir/form-some-name.php”。这使我得出结论,“form-some-name.php”由工作目录中的 main-page.php 以及位于 forms-dir 中的 form-carrier.php 注册,即mainpage.php 的子项。不应该像这样工作,但它可以工作。为避免混淆,我将同一目录“working-dir”中的两个包含文件(form-carrier.php;和 some-data-php)与“main-page.php”一起替换。
Now dir structure look like:
forms-dir (only error_log)
forms-byclass1-subdir (It contains files: form-some-name.php; error_log)
..... others forms-byclass-subdirs....
working-dir It contains files: (main-page.php; form-carrier.php; some-data-php; error_log)
And the php code in form-carrier.php:
...
<div id="include">
<?php
if (isset($_POST['strPath1'])) {
$strPath = $_POST['strPath1'];
var_dump($strPath);
require($strPath);
}
?>
</div>
...
我缩短了代码并决定不通过数据库,而是在 javascript 中创建具有完整路径的变量并通过 AJAX 直接将其发送到目标文件。结果还是一样的。如果通过键入记下路径,则代码将正确执行,如果我在 javascript 中使用由 Ajax 发送的变量,我会得到正确的数据,在 alert(html) 中可以从表单名称中读取所有数据。 php,以及form-carrier.php;和一些数据.php,var_dump($strPath);给了我正确的路径,但包含 div 仍然是空的!如果有人仍然有兴趣为解决这个问题做出贡献,我将非常感激,因为我未知和奇怪的问题。
【问题讨论】:
-
你是说
if条件内的echo $path而不是require($path)输出正确的路径? -
你有没有做过
var_dump($_POST)和 $path 看看那里有什么东西? -
您的 PHP 文件在哪里?
-
是的,它输出正确的路径并且与 require($path) 相同,否则 Ajax 将不会在成功时返回正确答案,这意味着它显示包含页面的完整内容,而不仅仅是成功消息。因此我使用 require 方法而不是 include,如果没有正确的路径,它会阻塞页面。也没有在应用程序中注册任何错误。只是它没有显示在指定的 div 中。 PHP包含文件位于运营商页面的子目录中,并存储在数据库中。
-
echo var_dump($_POST) 'returning string(9) name_form',这是 WERE 条件的正确字符串。和 mysqli_fetch_array($query);返回正确的拍子。
标签: javascript php html