phpjsonajaxajax4jsf

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. Search:

This is myscript
function showname(d) {
        var xhttp;
        if (window.XMLHttpRequest) {
            xhttp= new XMLHttpRequest();
        }else{
            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);
          xhttp.send();
    }
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.


Solution

  • 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);