accessing json values using .each
I am posting back some data from my server side code PHP to my client side
using Ajax , this is how its done
//server side
$json="{
"payout_history":"0",
"round_shares":"1816",
"workers":
{
"jbo.5970":
{
"alive":"1",
"hashrate":"1253"
},
"jbo.5970cpu":
{
"alive":"1",
"hashrate":"21"
},
"jbo.5970-2":
{
"alive":"1",
"hashrate":"1062"
}
}
}";
echo json_encode($json);
On the client side , i am trying to use the $.each function to iterate
over each worker to get the "jbo.5970" , "alive", "hashrate" . How do i go
about doing it
I tried this but nothing happen , no errors in debugger
//client side
$.ajax({
type: "POST",
url: "display.php",
data:{faculties:"arts"},
dataType: "json", //expect json to be returned
success: function(response){
$.each(response,function(i,item)
{
alert(response["workers"]);
});
}
});
No comments:
Post a Comment