我8天内收到内部服务器错误500,但找不到解决方法。
我想为我的用户制作一个搜索选项(当我得到它们时,哈哈)。我单独尝试了$.POST
方法,昨天我将其更改为$.ajax
post方法,并得到了相同的结果。
我认为错误来自网址属性。我测试了每一行代码并且确实有效,但是当我转到URL时,一切都变得地狱......每当我放置与"/wp-content/themes/yuuta/Food-Groups-BG.php"
不同的东西作为我的文件路径时,我得到404 NOT FOUND
当我把它还给我500 internal server error
...我已经阅读了我在互联网上找到的所有帖子,并尝试了很多解决方案,但它不会起作用......:X
这是我的JQuery和PHP。
jQuery(document).ready(function ($) {
$("#food_search").keyup(function(event){
var search_term =$(this).val();
$.ajax({
type:"POST",
url:"/wp-content/themes/yuuta/Food-Groups-BG.php",
data:{fsearch:search_term},
success:function(res){
$("#food_search_result").html(res);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<p>Търсене на храни: <input type="text" name="food-search" id="food_search"></p>
<!----------------------------------------------------------------
PHP
----------------------------------------------------------------->
<?php
$hostname = "localhost";
$username = "myName";
$password = "myPassword";
$databaseName = "dbName";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
if(isset($_POST['Title']) && $_POST['Title']!=""){
$fsearch = $connect->prepare("SELECT * FROM food_data_bg WHERE title LIKE :Title");
$fsearch->execute(array(
'Title'=>'%'.$_POST['Title'].'%'
));
if($fsearch->rowCount()==0){
echo 'Не бяха намерени резултати!';
}
else{
while($data=$fseach->fetch()){
?>
<div class="search-result">
<img src="<?php echo $data['fimage']; ?>" class="fimage"/>
<span class="result-title"><?php echo $data['title'];?></span><br>
<span class="calories-total"><?php echo $data['calories total'];?></span><br>
</div>
<?php
}
}
}else
{
echo 'Напишете име на продукт!';
}
?>