开发者

newbie json question

开发者 https://www.devze.com 2023-02-28 09:45 出处:网络
I have 2 files. 1: json.php; <?php $data = array( (object)array( \'oV\' => \'myfirstvalue\', \'oT\' => \'myfirsttext\',

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

精彩评论

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