Javascript 将json_编码的数组传递给jQuery

Javascript 将json_编码的数组传递给jQuery,javascript,php,jquery,ajax,json,Javascript,Php,Jquery,Ajax,Json,我正在尝试传递我正在使用json\u encode()在PHP中创建的数组。我正在运行一个AJAX请求,请参见以下内容: AJAX调用: $.ajax({ type: "POST", url: "../includes/ajax.php?imagemeta=1", data: { 'id' : $(this).attr('id') }, datatype:"json", suc

我正在尝试传递我正在使用
json\u encode()
在PHP中创建的数组。我正在运行一个AJAX请求,请参见以下内容:

AJAX调用:

$.ajax({
        type: "POST",
        url: "../includes/ajax.php?imagemeta=1",
        data: {
            'id' : $(this).attr('id')
        },
        datatype:"json",
        success: function(data) {
            console.log(data);
            console.log(data["image_height"]);
        },
        error: function(data) {
            console.log(data);
        }
    });
if(isset($_GET["imagemeta"])){

$id = intval($_POST["id"]);
$path = "../uploads/images/" . $fm->selectImageById($id);
$meta = array();

list($width, $height) = getimagesize($path);
$meta["image_height"]   = $height . 'px';
$meta["image_width"]    = $width . 'px';

print json_encode($meta);
PHP JSON响应:

$.ajax({
        type: "POST",
        url: "../includes/ajax.php?imagemeta=1",
        data: {
            'id' : $(this).attr('id')
        },
        datatype:"json",
        success: function(data) {
            console.log(data);
            console.log(data["image_height"]);
        },
        error: function(data) {
            console.log(data);
        }
    });
if(isset($_GET["imagemeta"])){

$id = intval($_POST["id"]);
$path = "../uploads/images/" . $fm->selectImageById($id);
$meta = array();

list($width, $height) = getimagesize($path);
$meta["image_height"]   = $height . 'px';
$meta["image_width"]    = $width . 'px';

print json_encode($meta);
}

尽管如此,console.log(data)返回以下内容:
{“image\u height”:“1374px”,“image\u width”:“920px”}

以下行console.log(数据[“image_height”])返回undefined

我已经尝试了多次尝试,并且已经阅读了大多数关于这个主题的顶级问题。我对JSON编码相当陌生,所以如果我有误解,请通知我

datatype:"json",
应该是:

dataType:"json",
    ^
Javascript区分大小写

应该是:

dataType:"json",
    ^

Javascript区分大小写。

如果console.log显示以下内容:-

{"image_height":"1374px","image_width":"920px"}
然后您可以访问“图像高度”,如下所示:-

data.image_height;

如果console.log显示以下内容:-

{"image_height":"1374px","image_width":"920px"}
然后您可以访问“图像高度”,如下所示:-

data.image_height;

设置php JSON响应头或从php返回纯文本,并在success函数中使用$.parseJSON

 success: function(data) {
        jSon = $.parseJSON(data);
        console.log(jSon.image_height);
    }

设置php JSON响应头或从php返回纯文本,并在success函数中使用$.parseJSON

 success: function(data) {
        jSon = $.parseJSON(data);
        console.log(jSon.image_height);
    }

我的天啊。我讨厌我的小错误,这些小错误使我一连好几个小时都感到厌烦。非常感谢!我的天啊。我讨厌我的小错误,这些小错误使我一连好几个小时都感到厌烦。非常感谢!请尝试
数据。图像高度
?尝试
数据。图像高度