[英]500 Internal Server Error on PHP calls
当我使用$.ajax
请求php
文件时,我总是遇到此问题,它总是返回500服务器错误,但仅当我将文件上传到服务器时才出现。 我在Windows 8.1和localhost
上完美运行XAMPP。
我已经尝试直接访问php
文件的网址,也给了我同样的错误。
阿贾克斯 :
function get_blog(reload_list){
var $titulo, $texto, $response, $post, $post_list;
var parameters = window.location.search;
$.ajax({
method: 'get',
url: '/php/blog.php' + parameters,
success: function(data){
if(data == "404"){
$("#blog").html("404 El articulo que buscas no existe");
} else {
$response = data;
$post_list = $response.post_list;
$titulo = $response.post.titulo;
$texto = $response.post.texto;
$("title#blog_title").html("IBR - " + $titulo);
$("h3#blog_title").html($titulo);
$("#blog_text").html($texto);
if(reload_list){
for(i=0; i<=$post_list.length; i++){
$("#post_list").append($post_list[i]);
}
}
}
}
});
PHP的 :
<?php
error_reporting(E_ALL);
ini_set('display_errors' 1);
$l = mysql_connect ( "localhost" , "myserver" , "mypass" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "mydb" ) or die("Error getting db:<BR><BR>".mysql_error());
if(!isset($_GET['post_id'])) {
$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$texto = stripslashes($row['texto']);
$post = [
'id' => $id,
'titulo' => $titulo,
'texto' => $texto
];
}else{
// echo $_GET['post_id'];
$post_id = $_GET['post_id'];
$query = mysql_query("SELECT * FROM mytable WHERE id=$post_id ORDER BY id DESC LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
if(empty($row)){
die("404");
}
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$texto = stripslashes($row['texto']);
$post = [
'id' => $id,
'titulo' => $titulo,
'texto' => $texto
];
}
$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$li = '<a class="text_decoration post_list_item" href="devocional.html?post_id='.$id.'"><li>'.$titulo.'</li></a>';
$post_list[]= $li;
}
$response = [
'post' => $post,
'post_list' => $post_list
];
$json_response = json_encode($response);
print_r($json_response);
?>
实际上,我无法访问我的error_log
。 还尝试通过以下方式查看错误:
error_reporting(E_ALL);
ini_set('display_errors' 1);
但是浏览器仅显示空白页。 我在使用PHP SDK
的Facebook API调用中也遇到了同样的问题。 我真的不知道该怎么办。 感谢您的提前帮助。
PHP直到5.4才支持当前使用的速记数组。 http://php.net/manual/en/migration54.new-features.php , http://php.net/manual/en/language.types.array.php
这是您的更新代码,该代码应该可以正常工作并与5.6向前兼容。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$l = mysql_connect ( "localhost" , "myserver" , "mypass" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "mydb" ) or die("Error getting db:<BR><BR>".mysql_error());
if(!isset($_GET['post_id'])) {
$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$texto = stripslashes($row['texto']);
$post = array(
'id' => $id,
'titulo' => $titulo,
'texto' => $texto
);
}else{
// echo $_GET['post_id'];
$post_id = $_GET['post_id'];
$query = mysql_query("SELECT * FROM mytable WHERE id=$post_id ORDER BY id DESC LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
if(empty($row)){
die("404");
}
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$texto = stripslashes($row['texto']);
$post = array(
'id' => $id,
'titulo' => $titulo,
'texto' => $texto
);
}
$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{
$id = stripslashes($row['id']);
$titulo = stripslashes($row['titulo']);
$li = '<a class="text_decoration post_list_item" href="devocional.html?post_id='.$id.'"><li>'.$titulo.'</li></a>';
$post_list[]= $li;
}
$response = array(
'post' => $post,
'post_list' => $post_list
);
$json_response = json_encode($response);
print_r($json_response);
?>
另外,这里的强制性说明...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.