我對從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。 –