有人幫助,我錯了! Ajax返回正確的信息。它還顯示'成功'包括頁面中的所有數據'alert(html)'。 Echo $ idName;和echo $ path;在載體頁面上打印正確的信息(代碼在哪裏)。頁面中沒有邊茶點。 Require方法不會阻止頁面。問題是div包含空的!謝謝。PHP包括/需要方法與變量路徑
<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,它自帶include some data.php'。一旦通過錨標籤,他將選擇適當的表格,這個表格應該包含在適當的「div = 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)
通過鍵入指定路徑測試,發現它正常工作,如果在題要求(「形式 - byclass1-子目錄/表單一些-name.php」);以及「../forms-dir/ forms-byclass1-subdir/form-some-name.php」。這使我的「的形式,一些-name.php」由主page.php文件是在工作-DIR註冊的結論,以及由位於窗體的DIR表單carrier.php,這是mainpage.php的一個孩子。不應該這樣工作,但它的工作原理。爲了避免混淆,我在同一目錄「working-dir」和「main-page.php」中替換了兩個包含文件(form-carrier.php;和some-data-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中使用一個變量,阿賈克斯派出去了,我得到正確的數據,在警報(HTML)可以閱讀的形式,一些名稱的所有數據。 PHP,以及form-carrier.php;和some-data.php,var_dump($ strPath);給我正確的路徑,但包括div仍然是空的!如果有人仍然有興趣幫助解決這個問題,我將非常感激,對我來說,這是一個未知和奇怪的問題。
你是說'回聲$ path'而不是'要求($ PATH)''的條件if'內輸出正確的路徑? –
您是否已經完成'var_dump($ _ POST)'和$路徑以查看填充了什麼內容? – Kitson88
你的PHP文件位於哪裏? –