So I'm trying to make a search like Netflix's and to explain, when you type a letter, the link changes so it's like this search.php?search=* whatever the query is * and it doesn't refresh the page and here's my take so far:
search.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="form">
<input type="text" id="search" placeholder="Search">
</form>
<script src="js/jquery.js"></script>
<script type="text/javascript">
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable) { return pair[1]; }
}
return(false);
}
function getSearchQuery() {
$.ajax({
type : 'GET',
url : 'functions/get.php',
data: 'search=' + getQueryVariable("search"),
success : function(html) {
$("#form").html(html);
}
});
}
$("#search").keyup(function(event) {
var query = $('#search').val();
event.preventDefault();
location.replace('search.php?search=' + query);
});
</script>
</body>
</html>
get.php
<?php
$search = isset($_GET['search']) ? $_GET['search'] : '';
echo '<input type="text" id="search" placeholder="Search" value="'.$search.'">';
?>
So my only problem is that it refreshes. Is there any way to stop it from refreshing and only update the link above?