我使用Plupload上傳文件,它工作正常。無法從Plupload獲取JSON數據
我測試了在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
爲空。
我在這裏做錯了什麼?
首先在安裝Firebug之類的東西之前,使用console.log作爲alert不能處理複雜的類型我想 - console.log會顯示所有對象的內容 – 2012-04-25 10:01:19
我已經是Firebug的常用用戶。做一個console.log或警報將顯示相同的結果 – Steven 2012-04-25 10:07:45
它不會實際上,警報將顯示「[對象對象]」,如果它不爲空,至少在Firefox中不會告訴你很多。我只是在該響應字符串上調用了parseJSON,並且它工作正常,因此在對象上調用它並不會爲你工作,這很奇怪 – 2012-04-25 10:26:05