我使用jQuery在PHP中运行一个函数来从数据库中获取数据。
$.ajax({
url: 'service.php',
data: { functie: type, param: radiobutton },
dataType: 'json',
success: function (data) {}
});一切正常。除了带有特殊字符的字符串在succes函数中返回为null。例如:ñ:
这里解释了这个问题的答案:Special characters break json returned to jQuery
但它对我不起作用。
在php中,我尝试了:
$result = mysql_query("SELECT * FROM wines");
$array = array();
while($row = mysql_fetch_assoc($result)){
$array[]=htmlentities($row);
}谁知道如何确保一切都以良好的方式返回呢?
发布于 2012-08-14 20:17:35
在while语句中,您在数组上使用htmlentities,而不是字符串(数组中的每个键都是数据库中的一列)。
您可以执行以下任一操作:
while($row = mysql_fetch_assoc($result)){
$array[] = array_map("htmlentities", $row);
}或者更改您的while循环:
while($row = mysql_fetch_assoc($result)){
foreach ($row as $key => $value) {
$row[$key] = htmlentities($value);
}
$array[] = $row;
}https://stackoverflow.com/questions/11951999
复制相似问题