2012-06-25 86 views
0

我正在使用jQuery的filedrop插件將圖像上傳到我的網站imgur。 PHP腳本返回{"status":"Imgur code: cZ8gH"}Filedrop JSON響應

我想將此作爲警報返回,但我無法弄清楚如何執行此操作?

我現在有這個

uploadFinished:function(i,file,response){ 
     $.data(file).addClass('done'); 
     var jsonobj = $.parseJSON(response); 
     alert(jsonobj.status); 
     // response is the JSON object that post_file.php returns 
    } 

但它不工作?

+1

也許響應已經被解析。 'response.status'工作嗎? – Thomas

+0

這是!謝謝,我沒有想到 –

+1

使用帶有控制檯(或Firebug Lite)的瀏覽器並調用'console.log'而不是'alert'總是更好。 – Thomas

回答

1

我不知道filedrop插件,但是當沒有指定dataType時,jQuery試圖使用MIME類型的響應來解析ajax響應。

因此,響應可能已經被jQuery解析。

使用

response.status 

爲了調試幫助它總是最好使用一個瀏覽器控制檯(或Firebug的精簡版),並調用

console.log 

而是採用alert尤其是因爲console可以打印嘗試物體

感謝@raina77ow