无法从Plupload获取JSON数据

时间:2012-04-25 09:57:00

标签: php jquery json plupload

我正在使用Plupload上传文件,它运行正常。

我已经测试了Stackoverflow上的各种建议,但我仍然无法从我的JSON响应中获得任何合理的数据。

在我的upload.php文件中,我有echo json_encode($result);

在我的JS中,我执行以下操作:

  uploader.bind('FileUploaded', function(up, file, response) {
    var obj = jQuery.parseJSON(response);
    var obj2 = eval(response);

    alert(response.toSource()); // <-- Outputs raw data
    alert(obj); // <-- is NULL
    alert(obj2.toSource()); // <-- Outputs eval data format
    alert(obj2.logo_url); // <-- Is not working
  });

alert(response.toSource());会返回此信息:

({response:"{
  \"logo_url\":\"http:\\/\\/mysite.com\\/uploads\\/3b\\/7b019482c806f9_logo.jpeg\",
  \"img_id\":\"30\",
  \"feedback\":{\"message\":\"File uploaded\",
  \"success\":true}}", 
  status:200})

obj为NULL。

我在这里做错了什么?

2 个答案:

答案 0 :(得分:3)

var uploader = $(“#multi_upload”)。pluploadQueue();

uploader.bind('FileUploaded', function (up, file, res) {
    var res1 = res.response.replace('"{', '{').replace('}"', '}');
    var objResponse = JSON.parse(res1);
    alert(objResponse.fn);
});

答案 1 :(得分:2)

有很多错误

  1. 删除引用转义\“
  2. 响应+状态应为引号
  3. {
        "response": {
            "logo_url": "http: \\/\\/mysite.com\\/uploads\\/3b\\/7b019482c806f9_logo.jpeg",
            "img_id": "30",
            "feedback": {
                "message": "Fileuploaded",
                "success": true
            }
        },
        "status": 200
    }
    
相关问题