下面是ajax代码。
问题在评论中
$.ajax({
type: "POST",
url: "dbtryout2_2.php",
data:datastr,
dataType: "json",
success: function(arrayphp)
{
//ARRAYPHP is a json array and iam displaying the
//contents of the array one by one as link
$.each(arrayphp, function(i, element) {
var link = $('<a href="#" class="album"><font color="red">' + element + '</font></a>');
var image='<input type="image" src="img4.jpg" height="30px" width="30px">';
$(".searchby .searchlist").append(image).append(link);
});
}
});
上面的代码不起作用。我没有正确使用 json 数组。下面是 php 代码/ PHP 代码/
if(!strcmp($_REQUEST['id'],'a2'))
{
$lang=$_REQUEST['lang'];$type=$_REQUEST['type'];
$query="select distinct(cat_name) from song where lang='$lang' and category='$type'";
$result=mysql_query($query,$con) or die("Query failed".mysql_error());
$arrayphp=array();
while($row=mysql_fetch_array($result))
{
$element=$row['cat_name'];
array_push($arrayphp,$element);
}
//here is the json array that is being sent to the above html code
echo json_encode($arrayphp);
}