title: How to call JS function through ajax call
body: <p>I want to call a jsp file through ajax post call. So I've done below code  - </p>
  
  <pre><code>  xmlhttp=new XMLHttpRequest();
  
     xmlhttp.onreadystatechange=function()
     {
     if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
       {  
      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
     }
     }
  
     var params = "report_id=0&amp;id=1234567890";
    xmlhttp.open("POST","/test/jsp/test.jsp",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  
        xmlhttp.setRequestHeader("Content-length", params.length);
        xmlhttp.setRequestHeader("Connection", "close");
      xmlhttp.send(params);
     }
     &lt;/script&gt;
      &lt;/head&gt;
  &lt;body onload="loadXMLDoc()"&gt;
   &lt;div id="myDiv"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Now test.jsp looks like below - </p>
  
  <pre><code>  &lt;html&gt;  
    &lt;head&gt;
     &lt;script language="JavaScript"&gt;
     function hello()
     {
     alert("Hello");
     //Do my stuff
      }
     &lt;/script&gt;
       &lt;title&gt;test Page&lt;/title&gt;
  
    &lt;/head&gt;
      &lt;body topmargin="0" leftmargin="0" onload="hello()"&gt;
    &lt;form name="mainForm" &gt;
    &lt;/form&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>Issue is, I'm not getting alert message when opening my first html page. What is wrong here and what needs to be done?</p>