how to run ajax with XMLHttpRequest and php

Here is the main file code index.php

<html>
        <head>
            <script>
                function recivemessage(str){     
                    var msz;        
                    if(window.XMLHttpRequest){
                        msz = new XMLHttpRequest();
                    }
                    else{
                        alert("failed");
                    }
            msz.open("GET","response.php?msg="+str,true);
            msz.send();
                }
            </script>
        </head>
        <body>
        <input type="button" value='ok' onclick="recivemessage('ssss')" >
        </body>
    </html>


--------------------------------
Here is the response code

<html>
    <body>
        <h1>Server1</h1>
    <?php
    $msg=$_GET['msg'];
    echo  $msg;
    ?>
    </body>
    </html>


Leave a Reply

Your email address will not be published. Required fields are marked *