Attempting to create a search engine using AJAX. When typing in the search box, nothing happens. After inspecting the element and opening the console, an error message is displayed:
script.js:19 GET http://localhost/var/www/html/pendaftaran-siswa/NaN 404 (Not Found)
Upon clicking on Sources, it shows that there was a failure to load sources on line 19. Below is the script being used:
var keyword = document.getElementById('keyword');
var searchButton = document.getElementById('search-button');
var container = document.getElementById('container');
keyword.addEventListener('keyup', function(e) {
const src = e.target.value
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if( xhr.readyState == 4 && xhr.status == 200) {
container.innerHTML = xhr.responseText;
}
}
xhr.open('GET', 'ajax/mahasiswa.php?keyword=' + keyword.value, true);
xhr.send();
});
Is there a solution to this issue? Apologies for any language errors.
UPDATE, the error message has now changed to:
Fatal error: Uncaught Error: Call to undefined function query() in S:\xampp\htdocs\var\www\html\pendaftaran-siswa\ajax\mahasiswa.php:11 Stack trace: #0 {main} thrown in S:\xampp\htdocs\var\www\html\pendaftaran-siswa\ajax\mahasiswa.php on line 11