I cannot get my input to be echo when I input text in my search field.
I do get the alert javascript but not the echo 2 to be display into the srv_search_mini_display field.
Im thinking that the ajax cant access the find_Service.php
search.php
<input id="service_search_box" class="form-control mr-sm-2" type="text" name="search" placeholder="Search Services..." oninput="searchService()">
<div id="service_search_div" class="srv_search_mini_display d-none"></div>
<script type="application/javascript">
function searchService(){
var srv_search = document.getElementById("service_search_box").value;
var param = "service_search_box="+srv_search;
if(srv_search.length > 0){
$("#search_search_div").removeClass("d-none");
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function(){
if(ajax.readyState === 4 && ajax.status === 200){
if(ajax.responseText === ""){
document.getElementById("service_search_div").innerHTML = "";
$("#service_search_div").addClass("d-none");
} else {
alert(param); document.getElementById("service_search_div").innerHTML = ajax.responseText;
}
}
};
ajax.open("POST",'find_Service.php',false);
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajax.send(param);
} else{
document.getElementById("service_search_div").innerHTML = "";
$("#service_search_div").addClass("d-none");
}
}
</script>
find_Service.php
<?php
require_once('database.php');
$heidisql = pdo_con();
echo 2; // does not even appear
?>
<div id="service_search_div" class="srv_search_mini_display d-none"></div>document.getElementById("service_search_div").innerHTML = ajax.responseText;why this in the comment section. it should be in the next line to set the HTML.