无法访问函数中的json数据

时间:2015-12-07 11:24:49

标签: jquery json dropzone.js

我从服务器获取此数据作为JSON响应:

{
    "success": true,
    "status": "success",
    "path": "http:\/\/www.images.site.com\/profile\/large\/",
    "smallpath": "http:\/\/www.images.site.com\/profile\/small\/",
    "smpath": "http:\/\/www.images.site.com\/profile\/sm\/"
}

如何在jQuery成功时访问它?我试过这个:

$(document).ready(function () {
    $("#img").dropzone({
        paramName: "file",
        maxFiles: 1,
        url: 'http://images.site.com/aac.php',
        init: function () {
            this.on("success", function (file, dd) {
                console.log("log " + dd.length);
                console.log("log " + dd.success);
                console.log("sd" + dd.path);
            }).fail(function () {
                alert("error");
            });
         }
        });

我收到错误:

  

log来自服务器的无效JSON响应

我使用dropzone.js进行文件上传

1 个答案:

答案 0 :(得分:0)

尝试更改

dd.length

到这个

Object.keys(dd).length

我尝试console.log(dd.length),它显示undefinedObject.keys(dd).length效果很好。

相关问题