I cannot seem to populate the autocomplete list of the Product Names that I am fetching through AJAX from my DATABASE. For some reason, the list shows only "Array" and not the actual name of the products. There is no problem with the SQL. This is my code -- Help would be appreciated. Thanks in advance.
PHP File:
<?php require_once("BusinessLogic/ProductCRUD.php");
$productsCrud = new ProductCRUD();
$productNames = $productsCrud->GetProductNames($_POST["products"]);
?>
<html>
<head>
<script type="text/javascript" language="javascript" src="ajax.js"></script>
</head>
<body>
<form>
<input type="text" id="products" placeholder="Product Name " style="width:200px" list="productsList" onkeydown="javascript:ajax_post()"/>
<datalist id="productsList">
<select name="prodList">
<?php
foreach ($productNames as $pN)
{
echo "<option value='" . $pN . "'>" . $pN . "</option>";
}
?>
</select>
</datalist>
</form>
</body>
</html>
AJAX Javascript:
function ajax_post(){
var hr = new XMLHttpRequest();
var url = "html5test.php";
var pl = document.getElementById("products").value;
var vars = "products="+pl;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.send(vars);
}

New Topic/Question
Reply




MultiQuote





|