[英]POST 500 Internal Server Error — PHP
該代碼在本地主機上運行良好
並上傳到服務器后,我發現了這一點:無法加載資源:服務器的狀態為500(內部服務器錯誤)
以及其他一些時間:POST $ link 500(內部服務器錯誤)
WordPress的!
AJAX代碼:
function fetch_select(val) {
$.ajax({
type: 'post',
url: 'test2.php',
data: {
get_option:val
},
success: function (response) {
$('.restaurnat').html(response);
}
});
}
PHP代碼:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['get_option'])) {
if (!empty($_POST['get_option']) && $_POST['get_option'] != 0) {
global $wpdb;
$rests = $wpdb->get_results("SELECT * FROM Cities WHERE ID = $_POST['get_option']", ARRAY_A);
if (!empty($rests)) {
foreach ($rests as $rest) {
echo "<option value='" . $rest['ID'] . "'>" . $rest['res'] . "</option>";
}
}
} else {
echo "<option value=''> --- Choose Country or City First --- </option>";
}
}
}
?>
HTML代碼:
<div class='container'>
<h1 class='text-center'>Choosing requests</h1>
<form class='text-center form-horizontal' style='padding:10px;max-width:400px;margin:auto;' action="<?php echo $_SERVER['PHP_SELF']; ?>" method='POST'>
<h1 class="text-center" style='font-size:3.9em;margin:40px 0;font-weight:bold;'>Choose City or Country</h1>
<select name='city' onchange='fetch_select(this.value)'>
<option value=''>--- Choosing City or Country ---</option>
<?php
global $wpdb;
$q = $wpdb->get_results("SELECT City_Name, ID FROM Cities ORDER BY ID ASC", ARRAY_A);
if (!empty($q)) {
foreach ($q as $city) {?>
<option value="<?php echo $city['ID']; ?>"><?php echo $city['City_Name']; ?></option>
<?php
}
} else {
echo "<div class='container'><div class='alert alert-warning'><p class='lead'>There is no city or Country at the database</p></div></div>";
}
?>
</select>
<br />
<h1 class="text-center" style='font-size:3.9em;margin:40px 0;font-weight:bold;'>Choose restaurant</h1>
<select name='restaurant' class='restaurnat'>
<option value=''>--- Choose Country or City first ---</option>
</select>
<input type='submit' value='Order now' class='btn btn-lg btn-primary' style='margin:10px;'/>
</form>
</div>
問題是:我忘了做:
require_once('wp-config.php');
在頁面的開頭!
您需要定位admin-ajax.php
來處理WordPres中的AJAX requet。
function fetch_select(val) {
$.ajax({
type: 'post',
url: 'http://example.com/wp-admin/admin-ajax.php',
data: {
get_option:val
},
success: function (response) {
$('.restaurnat').html(response);
}
});
}
關於WordPress AJAX, 此答案也可能對您有幫助。
檢查您的ht-access文件,並將本地URL替換為數據庫中的實時URL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.