jquery - 如何从 Jquery 中的成功回调中检索数组值
问题描述
我想从 nodejs 获取数组数据。特别是我期待获得我使用 Jquery 检索数据但我做不到的每个结果的文件名。我不知道该怎么做。
router.post('/womensearch',(req,res)=>{
const searchItem = req.body.womenitem;
// If it is Catagory
gfs.collection('wdress').find({
$and:[{ $or : [{'metadata.cat': searchItem},{'metadata.brand':
searchItem}]}]
}).toArray((err,files)=>{
res.end(JSON.stringify(files)); <- Here is my problem
});
});
这是jQuery代码
function womenSearch(){
$(document).ready(function(){
const search_item = $('#womenItem').val();
$.ajax({
method:'POST',
url:'/womensearch',
cache:false,
data:{
womenitem:search_item
},
success:function(data){
},
error:function(){
}
});
});
}
</script>
这是我从数据库中得到的结果。
{ _id: 5c62dfbf87dda7249c87c190,
length: 129450,
chunkSize: 261120,
uploadDate: 2019-02-12T15:01:19.617Z,
filename: 'd03e3359c03a5d885e85d6a48c6424a5.jpg',
md5: '88f70c2f16f1367fe7198775a3912daa',
contentType: 'image/jpeg',
metadata:
{ brand: 'Mango',
cat: 'Coats',
name: 'Harish',
color: 'Blue',
price: '2750',
info: 'Stylish gesture for women ',
dis: '50',
Likes: 2 } },
{ _id: 5c62e3d20a7a574dbc7c0044,
length: 150261,
chunkSize: 261120,
uploadDate: 2019-02-12T15:18:42.036Z,
filename: 'eb1528f1e7e9707f2d79a6d97981a9c8.jpg',
md5: '08c1bcd73521e00f6b4857363f950e52',
contentType: 'image/jpeg',
metadata:
{ brand: 'Mango',
cat: 'Coats',
name: 'Harish',
color: 'Blue',
price: '5000',
info: 'This is wonderful ',
dis: '0',
Likes: 0 } } ]
通过 Jquery 回调函数发送数据的任何提示。
解决方案
您需要json
在访问结果之前将其解析为。
resultJSON = JSON.parse(data);
推荐阅读
- javascript - JavaScript 中的多列
- firebase - 有firebase的测试账户吗?还是恶意的?
- python - 打印numpy数组时仅删除零值的科学记数法?
- css - 在这种情况下,如何将圆(在 pesudo 类中:after)和文本垂直居中对齐?
- java - 在全栈 Web 应用程序中验证表单数据的最佳方式(Spring boot + React JS)
- java - 如何将 jar 库中的方法头显示给客户端应用程序?
- javascript - 使用 Puppeteer/NodeJS 在单击时设置 FormData 键/值
- python - 递归函数嵌套字典python
- php - 我想将其限制为仅添加一个类别的产品,而不允许使用 woocommerce 的其他产品
- python - 我如何解决这个 python 大学问题?