jvk jvk - 5 months ago 12
JSON Question

how to call name onkey up using ajax?

i am new to ajax. I want to get name from the database according to onkey up but i am getting this error in console "Invalid left-hand side in assignment". and when i type its showing "showname function is not defined".?
This is my code.


This is myscript
function showname(d) {
var xhttp;
if (window.XMLHttpRequest) {
xhttp= new XMLHttpRequest();
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
xhttp.open("POST", "ajax2.php?name"=+d, true);
this ajax2.php code

$name = $_GET["name"];
$db = new mysqli("localhost", "root", "", "customername");
$conn = $db->query("select customerName from customers like '".$name."%'");
$fetch = $conn->fetch_array();

<?php foreach ($fetch as $key => $value) :?>
<p><?php echo $value ?></p>
<?php endforeach; ?>

Thanks you in advance.


xhttp.open("POST", "ajax2.php?name"=+d, true);

I think you got a typo there, put the = into the quote marks.

xhttp.open("POST", "ajax2.php?name=" + d, true);