确定来自jQuery的PHP的响应 [英] Determine response from PHP in jQuery

查看:66
本文介绍了确定来自jQuery的PHP的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部, 我有一个基本上在上载完成时触发的函数.我在该函数中有以下代码:

All, I've got a function that basically gets triggered when an Upload finishes. I have the following code in that function:

onFinish: function (e, data) {
    console.log(data.result);
},

当我这样做时,我会在控制台中收到以下响应:

When I do this I get the following response in my console:

[{
    "name": "1_3266_671641333369_14800358_42187036_5237378_n.jpg",
    "size": 35535,
    "type": "image\/jpeg",
    "url": "\/web\/upload\/1_3266_671641333369_14800358_42187036_5237378_n.jpg",
    "thumbnail_url": "\/web\/upload\/thumbnails\/1_3266_671641333369_14800358_42187036_5237378_n.jpg",
    "delete_url": "\/web\/upload.php?file=1_3266_671641333369_14800358_42187036_5237378_n.jpg",
    "delete_type": "DELETE",
    "upload_type": "video_montage"
}]

我想获取upload_type中的值并基于该值执行一些操作,但是我不确定如何从函数中获取它.任何帮助将不胜感激,以获取此信息.

I'd like to get the value that is in the upload_type and do some actions based on that but I'm not sure how to get this from my function. Any help would be appreciated to get this information.

谢谢!

推荐答案

data.result是一个数组,您需要访问第一个元素,然后访问upload_type.

data.result is an array, you need to access the first element and then access upload_type.

尝试console.log(data.result[0].upload_type);

更新: 如果data.result是字符串,则需要先对其进行解析.尝试

Update: If data.result is a string, you need to parse it first.Try

var result = JSON.parse(data.result); 
console.log(result[0].upload_type);

这篇关于确定来自jQuery的PHP的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆