Saturday, 31 August 2013

how to display elements of json array returned from php within a loop in ajax(jquery)

how to display elements of json array returned from php within a loop in
ajax(jquery)

Below ajax code is receiving a json array from php. Rest details i have
written as comments:
$.ajax({
type: "POST",
url: "dbtryout2_2.php",
data:datastr,
cache: false,
//dataType: 'json',
success: function(arrayphp)
{
//"arrayphp" is receiving the json array from
php.
//below code is working where iam displaying
the array directly
//This code displays the array in raw format.
$(".searchby .searchlist").append(arrayphp);
}
});
But when iam trying to display the elements of the array seperately using
below code ,then it is not working:
$.ajax({
type: "POST",
url: "dbtryout2_2.php",
data:datastr,
dataType: "json",
cache: false,
contentType: "application/json",
success: function(arrayphp)
{
//nothing is getting displayed with this code
$.each(arrayphp,function(i,v){
alert(i+"--"+v);
});
}
});
WOULD ANYBODY FIGURE OUT WAT THE PROBLEM IS WITH MY CODE?

No comments:

Post a Comment