Php Filedrop JSON响应
我正在使用用于jquery的filedrop插件将图像上传到我网站上的imgur。PHP脚本返回Php Filedrop JSON响应,php,javascript,jquery,json,Php,Javascript,Jquery,Json,我正在使用用于jquery的filedrop插件将图像上传到我网站上的imgur。PHP脚本返回{“status”:“Imgur code:cZ8gH”} 我想将此作为警报返回,但我不知道如何执行此操作 我现在有这个 uploadFinished:function(i,file,response){ $.data(file).addClass('done'); var jsonobj = $.parseJSON(response); ale
{“status”:“Imgur code:cZ8gH”}
我想将此作为警报返回,但我不知道如何执行此操作
我现在有这个
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
}
但它不起作用?我不知道filedrop插件,但当没有指定数据类型时,jQuery尝试使用响应的MIME类型解析ajax响应 因此,jQuery可能已经解析了响应 试用
response.status
为了帮助调试,最好使用带有控制台(或Firebug Lite)的浏览器并调用
console.log
而不是使用警报
,特别是因为控制台
可以打印对象
由于的原因,可能已经解析了响应。
response.status
有效吗?是的!谢谢,我没有想到,使用带有控制台(或Firebug Lite)的浏览器并调用console.log
而不是alert
@Thomas也许你应该从你的评论中做出一个回答,这样你就可以得到信任了?)因为这是一个答案:默认情况下(如果ajax调用参数中没有发送数据类型),jQuery尝试从其内容猜测响应类型——如果结果是JSON,则自动解析它。)如果我正确阅读了文档,jquery只使用mime类型,而不使用内容来描述响应的类型。在本例中,它看起来可能是解析它的插件。