<?php
$data = array(
array(
'title' => 'Arduino #1',
'id' => 1,
'image' => 'http://www.casemods.ru/templates/images/texts/3_4119479.jpg',
'top' => 200,
'left' => 300,
'width' => 800,
'height' => 760,
'points' => array(
'id' => 1,
'objectId' => 1,
'top' => 300,
'left' => 500,
'tip' => 500,
),
),
array(
'title' => 'Arduino #2',
'id' => 2,
'image' => 'img/objects/arduino.png',
'top' => 200,
'left' => 300,
'width' => 800,
'height' => 760,
'points' => array(
'id' => 1,
'objectId' => 2,
'top' => 300,
'left' => 500,
'tip' => 500,
),
)
);
echo json_encode($data);
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: 'http://test_php_json_page/',
dataType: 'json'
}).done(function(data){
$.each(data, function(key, value){
console.log(key, ' :', value);
})
}).fail(function(){
console.log('error');
});
});
</script>
<?php
$data = array(
array(
'title' => 'Arduino #1',
'id' => 1,
'image' => 'http://www.casemods.ru/templates/images/texts/3_4119479.jpg',
'top' => 200,
'left' => 300,
'width' => 800,
'height' => 760,
'points' => array(
'id' => 1,
'objectId' => 1,
'top' => 300,
'left' => 500,
'tip' => 500,
),
),
array(
'title' => 'Arduino #2',
'id' => 2,
'image' => 'img/objects/arduino.png',
'top' => 200,
'left' => 300,
'width' => 800,
'height' => 760,
'points' => array(
'id' => 1,
'objectId' => 2,
'top' => 300,
'left' => 500,
'tip' => 500,
),
)
);
?>
<script type="text/javascript">
var data = <?php echo json_encode($data); ?>;
console.log(data[0]["title"]);
</script>