jquery getjson、php、mysql、500内部服务器错误
我尝试将字符串传递到第一个php页面,并将第二个php页面传递到另一个服务器,然后将json代码返回到第二个php页面 我发现了一个内部服务器错误,在jquery行7180 xhr.send s.hasContent&&s.data | null;我已经测试了sql连接和查询,它们都很好。请帮我找出哪里出了问题。 代码如下: 第二个php页面jquery getjson、php、mysql、500内部服务器错误,php,jquery,mysql,json,internal-server-error,Php,Jquery,Mysql,Json,Internal Server Error,我尝试将字符串传递到第一个php页面,并将第二个php页面传递到另一个服务器,然后将json代码返回到第二个php页面 我发现了一个内部服务器错误,在jquery行7180 xhr.send s.hasContent&&s.data | null;我已经测试了sql连接和查询,它们都很好。请帮我找出哪里出了问题。 代码如下: 第二个php页面 <html> <head> <script src="http://code.jquery.com/jquery-1.5.j
<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<?php $country = $_GET['country']; ?>
<script>
$(document).ready(function(){
var country = "<?php Print($country); ?>";
$.getJSON('json-data.php', {country: country},function(data) {
$('#mortality').html(html);
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "body" );
});
});
</script>
</head>
<body>
以及php服务器代码
<?php
$country = $_REQUEST['country'];
// Connecting, selecting database
$username = "root";
$password = "password";
$host = "localhost";
$database="disease";
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
$query = "select * from mortality where countryName = '$country';";
$mortality=array();
while($row=$mysql_fetch_object($query)){
$mortality.push($row);
unset($row);
}
echo json_encode($mortality);
mysql_close($server); ?>
检查web服务器的错误日志。另请阅读,$DETARITY.push$row在PHP中应该是$DETARITY[]=$row。这可能就是你的问题所在。请不要使用mysql_connect,请使用PDO或mysqli等同物。有关更多信息,请参阅。关于主题更改$DETARITY.push$行,使用数组_push$DETARITY,$row;您还应该添加一个标题“Content-Type:application/json”;以上echo json_编码$死亡率;非常感谢你!问题在于json格式化@Phil,并且fyrye中缺少内容类型。非常感谢。