Last active
April 4, 2017 08:38
-
-
Save elisedeux/b2a35d0d338eede99bd65aed81237d17 to your computer and use it in GitHub Desktop.
Retrieving nodes list and displaying the result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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