Reputation: 13
I have this problem when I request to a php
file using $.ajax
it always return me a 500 server error, but only when I upload the files to my server.
I use XAMPP on Windows 8.1 and in the localhost
runs perfectly.
I've tried accesing the url of the php
file directly and also gives me the same error.
Ajax:
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);
?>
Actually I don´t have access to my error_log
. Also tried to see errors through the:
error_reporting(E_ALL);
ini_set('display_errors' 1);
But the browser only shows a blank page. I have this same issue on a Facebook API call using the PHP SDK
too. I really don't know what to do. Thanks for helping in advance.
Upvotes: 1
Views: 2345
Reputation: 23892
PHP didn't support the shorthand arrays as you're currently using until 5.4. http://php.net/manual/en/migration54.new-features.php, http://php.net/manual/en/language.types.array.php
Here's your updated code which should work and be forwards compatible with 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);
?>
Also, obligatory notes here...
Upvotes: 0