2012-06-25 42 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