I'm a junior in college so i'm not fully experienced in coding just yet; However recently I got an internship and I was assigned a task to create a website that connects to the ninox database. So far i've been able to properly connect to the API endpoints and receive the JSON that contains all of the records stored in a specific database. Now i'm trying to work on a function that searches through the JSON file and returns values that match what was in the search box. Looking online for a solution I was able to find functions that use the JQuery RegEx() function but i'm not exactly sure how to implement that,and also i'm trying to store the JSON data into a variable and i'm not sure if its formatted correctly. Heres my current code:
//current fucntion function search(){ //gets value from search bar. not sure if this even needs to be used if regEx is used. let sName = document.getElementById('searchBar').value; var entry; sName = sName.toUpperCase();
//connects to API endpoint
var request2 = new XMLHttpRequest();
var accessToken = 'my token is here';
request2.open('GET','my URL is here');
request2.setRequestHeader('Authorization', 'Bearer ' + accessToken);
//function that stores the JSON reply into a variable
request2.onload = function(){
// this contains the JSON data
var data = JSON.parse(this.response)
if (request2.status >= 200 && request2.status < 400) {
//this currently just stores JSON data on webpage for testing purposes
document.getElementById("JSON").innerText += JSON.stringify(data);
} else {
alert('error');
}
}
request2.send();
alert(sName);
}
The JSON it returns is: JSON
I'm trying to search through both the Title and Synopsis Keys for matching strings. Any ideas that would help me achieve this would be greatly appreciated!