I'm analyzing this CodePen's code, which lets the user search any item within Wikipedia (through Wikipedia's API), and the search engine shows the first 10 results and brief summaries. Analyzing other people's code is (IMO) one of my best ways to learn, along with reading guidebooks and finishing tutorials.
The AJAX code I couldn't understand, is this:
$.ajax({
url: "https://en.wikipedia.org/w/api.php",
jsonp: "callback",
dataType: 'jsonp',
data: {
action: "query",
list: "prefixsearch",
pssearch: $(".searchbox").val(),
pslimit: "10",
format: "json"
},
xhrFields: {
withCredentials: true
},
success: updateSuggest,
error: function(err) {
console.log(err);
}
});
Idont understand what these 4 data parameters (action
, list
, pssearch
, pslimit
) do. What exactly are these 4 parameters' functions... can someone explain them? For example, what does pssearch
and list
and pslimit
do?
I tried looking these terms up on the API, jQuery website and Google searches, but no avail.
These properties are for searching the title prefix:
action: "query"
: Queries for data action.list: "prefixsearch"
: "Perform a prefix search for page titles." (docs, prefixsearch)pssearch
: The search string. - (docs)pslimit
: Limit the number of entries to returned. - (docs)The Prefixsearch has a short explanation of most of these parameters.