开发者

newbie json question

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;
?>
  1. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜