I have 2 files.
1: json.php;
<?php
$data = array(
(object)array(
'oV' => 'myfirstvalue',
'oT' => 'myfirsttext',
),
(object)array(
'oV' => 'mysecondvalue',
'oT' => 'mysecondtext',
),
);
$json = json_encode($data);
echo $json;
?>
test.html:
$(function () { $.ajax({ url: "json.php", dataType: "json", success: function(data){ console.log(data); } }); });
But i dont see my data object in the console. What did i miss? Than开发者_开发技巧ks!
You have to add this:
header("Content-type: text/plain");
echo json_encode($data);
This tells the browser what its retrieving.
精彩评论