Menu

Wednesday, July 20, 2011

Ajax call using java script

<html>
  <head>    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    function callAjaxFn(){
        var http;
        if (window.XMLHttpRequest){
                http = new XMLHttpRequest();
        } else {
                http = ActiveXObject ("Microsoft.XMLHTTP");
        }
        http.open("GET", "test.html", true);
        http.send();
        http.onreadystatechange=function(){
            if (http.readyState == 4 && http.status == 200) {
                alert(http.responseText);
            }
        }
    }
    </script>
  </head>
  <body>    
      <button onclick="callAjaxFn();" >Click Me</button>      
  </body>
</html>