I got this in my html :
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script>
$.post("mm.php", { func: "getNameAndTime" },
function(data){
$(data).each(function() {
$("div").append($(this).name);
});
}, "json");
</script>
<div></div>
And my mm.php looks like this :
<?php echo json_encode(array("my" => array("name"=>"John","time"=>"2pm"), "ur"=>array("name"=>"Nah","time"=>"1:13")) ); ?>
This was working before i putted the .each() so doesnt have the including or other problems.
Why isnt this working ?
Where have i been going wrong ?
datais not a DOM element, it’s a JSON object. You need to use$.eachinstead of.each()Also, inside theeach(),thisis an object, not a DOM element, so you don’t need$()around it.EDIT: Instead of using
thisinside theeachtry this: