how to fetch data using json and php : How to fetch json result using mysql connection
       $conn = new mysqli("localhost", 'root', "", "laravel");
        $query = mysqli_query($conn,"select * from customers");
        while($result2=mysqli_fetch_assoc($query)) {
            echo "Name: ".$result2['customerName'];
            echo "<br/>";
            }
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>JSON</title>
            </head>
            <body>

            <div id="demo"></div>


                <script>
                var xmlhttp = new XMLHttpRequest();
                var url = "connection.php";
                xmlhttp.onreadystatechange = function() {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    myFunction(xmlhttp.responseText);
                }
                }
            xmlhttp.open("GET", url, true);
            xmlhttp.send();

            function myFunction(response) {
                var arr = JSON.parse(response);
                var out = $result2;
                document.getElementById("demo").innerHTML = out;
            }
                </script>
            </body>
            </html>

            how to fetch the result using json and php and i want to know ajax    for json will work or not