I'm attempting to create a live search page for my database and running into an issue. My jQuery / Ajax does not seem to be working. My compiler is telling me that "$ is not defined" on my document line but I have defined jQuery and used the $(document).ready(function() call. Can anyone shed any light as to what seems to be the issue? I've googled and checked here and I can't find the solution.
Below are some code snippets and a screenshot of what I'm seeing. It looks like the query is working fine, detecting a result, but the jQuery is not displaying the result live as it should be.
jQuery:
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.search-box input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("backend-search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".result p", function(){
$(this).parents(".search-box").find('input[type="text"]').val($(this).text());
$(this).parent(".result").empty();
});
});
</script>
</head>
<body>
<div class="search-box">
<input type="text" autocomplete="off" placeholder="Search Books..." />
<div class="result"></div>
</div>
</body>
</html>
In the below images I'm trying to search for an entry containing the title "accounting". When I search correctly, it looks like a record appears but no data is shown. When I type something not fitting a record, it correctly displays no results.
Any and all help is greatly appreciated!
`
– Ikhlak S. Apr 22 '17 at 15:50