I have tried to access the title value inside the query, I am using the Wikipedia API, I have tried with:
query[search]
//También con
var obj = JSON.parse(query);
var nombre = obj['search'];
Request source code with jquery
$(".searchBox").on("change", function() {
var searchTerm = $("#searchTerm").val();
var url = "https://es.wikipedia.org/w/api.php?action=query&list=search&srprop=snippet&format=json&origin=*&utf8=&srsearch=" + searchTerm;
$.ajax({
url: url,
type: 'GET',
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function(data, status, jqXHR) {
console.log(data);
//no funciona
console.log(query[search])
}
})
});
You receive the API response through the variable
data
so you can access the json structure as follows,data.query.search
which is the part of interest; from here there is an arrangement, which you can continue processingYou have to verify the structure of the object, according to the image it has the following structure:
Therefore, to access the data you require, you should do it as follows: