Skip to content

Instantly share code, notes, and snippets.

@elisedeux
Last active April 4, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elisedeux/b2a35d0d338eede99bd65aed81237d17 to your computer and use it in GitHub Desktop.
Save elisedeux/b2a35d0d338eede99bd65aed81237d17 to your computer and use it in GitHub Desktop.
Retrieving nodes list and displaying the result
// Use the REST API to search for a term
function searchCustomer(term) {
// Configure and send the Ajax query asynchronously.
$.ajax({
type: "GET",
// REST method url
url: "http://localhost:3000/api/1cf9e65b/search/nodes/full",
// Define the authentication information.
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + btoa('root@root.com:6160b54b872459ce1c06c1a8ccdd9019')
},
// Message parameters
dataType: 'json',
data: {
q: `${term}`
}
}).fail( () => {
// On error, display an alert.
alert( "Error" );
}).done(data => {
// When the response arrives, update the result area
let results = document.querySelector("#matches");
results.textContent = '';
data.forEach(e => {
results.textContent += e.categories[0] + ' - ' + (e.data.fullname || e.data.name) + '\n';
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment