我使用WordPress平臺與PHP和MYSQL爲了創建一個網站,我有一個頁面,其中包括4個下拉列表,從MYSQL數據庫獲取數據並使用javascript和AJAX我是試圖使這些下拉列表相互依賴,其中用戶從第一個下拉列表中選擇並基於用戶的選擇第二個下拉顯示數據。在wordpress中找不到錯誤404頁面
問題是我已經使用了2個代碼來使AJAX工作而不刷新大廳頁面。
當我嘗試在調試模式下,它顯示的第一下拉列表中選擇:
404 drpdown_fetch_owner.php錯誤頁面沒有找到
目錄結構:
的/ opt/lampp/htdocs/wordpress/wp-content/themes/wp-portfolio/search_info_location.php
/o PT/LAMPP/htdocs中/ WordPress的/可溼性粉劑內容/主題/ WP-組合/ dropdown_fetch_owner.php
表:
site_info:
- SITEID
- 網站名稱
- ownerID
- 列表項目
OWNER_INFO:
- OWNERID
- OWNERNAME
問題:
第一droplist 可變OWNERID在AJAX留空時,用戶點擊後並沒有得到任何價值。
我在dropdown_fetch_owner.php代碼 添加var_dump($sql);
SQL查詢下我得到在調試模式這樣的說法:
的/ opt/LAMPP/htdocs中/ WordPress的/可溼性粉劑內容/主題/ WP-組合/ dropdown_fetch_owner.php:6: 陣列(大小= 0) 空
CODE1:
<form method ="post" action ="" name="submit_form">
<table border="0" width="30%">
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
</tr>
<tr>
<td><select id="site_name" name = "site_name">
<?php
$query_site_name =$wpdb->get_results("select DISTINCT siteNAME from site_info");
foreach($query_site_name as $row)
{
// $site_name = (array)$site_name;
echo "<option value = '".$row ->ownerID."'>".$row->siteNAME."</option>";
}
?>
<!--create dropdown list owner names-->
</select></td>
<td><select id="owner_name" name ="owner_name">
<option value="">Select Owner</option>
<!-- the below part of code work as it should --!>
<!--create dropdown list site names-->
<form method ="post" action ="" name="submit_form">
<table border="0" width="30%">
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
</tr>
<tr>
<td><select id="site_name" name = "site_name">
<?php
$query_site_name =$wpdb->get_results("select DISTINCT siteNAME from site_info");
foreach($query_site_name as $row)
{
// $site_name = (array)$site_name;
echo "<option value = '".$row ->ownerID."'>".$row->siteNAME."</option>";
}
?>
<!--create dropdown list owner names-->
</select></td>
<td><select id="owner_name" name ="owner_name">
<option value="">Select Owner</option>
<script type="text/javascript">
// make Dropdownlist depend on each other
$(document).ready(function(){
$('#site_name').change(function(){
var ownerID = $(this).val();
$.ajax({
url:"dropdown_fetch_owner.php",
method:"POST",
data:{ownerID:ownerID},
datatype:"text",
success:function(data){
$('#owner_name').html(data);
}
});
});
});
</script>
dropdown_fetch_owner。PHP:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-load.php');
global $wpdb;
$sql =$wpdb->get_results("select * from owner_info where ownerID = '".$_POST['ownerID']."' ORDER BY ownerNAME");
echo '<option value="">Select Owner</option>';
foreach($sql as $row){
//while ($row = mysqli_fetch_array($result)) {
echo "<option value = '".$row ->ownerID."'>". $row->ownerNAME."</option>";
}
?>
請你共享的文件的目錄結構 –
@TamilSelvanC我加入文件結構 –
就像這樣'url:「<?php echo get_stylesheet_directory_uri();?>/dropdown_fetch_owner.php」,'在'$ .ajax({' –