我对从sql查询中提取的数据有一个ajax响应。它有这样的结构:在javascript中搜索ajax请求元素的索引
Response
id:"id"
titulo:"title"
url:"url"
我想要做的是找到在给定的唯一ID是ajax响应内的位置。
$.ajax({
url: 'select.php',
type: 'get',
data: {
"id": id
},
dataType: "json",
beforeSend: function() {},
success: function(response) {
console.log(response);
console.log(response.indexOf(27188964));
}
});
第二个日志打印-1
,知道该数字应该在第一个位置。
编辑: 我需要为了通过增加“索引” response[index].url
什么它是否意味着响应指数? – Ray
你能否贴上回应? – brk
indexOf通常在搜索词没有结果时返回-1。 –