Using JavaScript to send a request to a method in Spring controller, the code looks like this:
<script language="javascript" type="text/javascript">
var xmlHttp
function show()
{
if(typeof XMLHttpRequest != "undefined")
{
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlHttp==null)
{
alert("Browser does not support XMLHTTP Request")
return;
}
var FAC_LICENSE_NO=document.getElementById("FAC_LICENSE_NO").value;
//var url="/Final/WEB-INF/jsp/SurrenderViews/Ajax.jsp";
var url="http://localhost:8080/Final/Ajax.FSu";
url +="?param1="+FAC_LICENSE_NO;
alert(url);
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange()
{
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("factoryname").innerHTML=xmlHttp.responseText
}
}
</script>
and the corresponding controller is:
public class PhaseTwoFormSurrenderOfLicense extends MultiActionController implements Connections {
public ModelAndView DataInput(HttpServletRequest request,HttpServletResponse response)
{
return new ModelAndView("SurrenderViews/DataInput");
}
public String Ajax(HttpServletRequest request,HttpServletResponse response)
{
System.out.println("Maritammanafvara");
String returning="<input type=\"text\" style=\"border: none\" name=\"Factory_name\" readonly=\"readonly\" value=\"HIHI\">";
return returning;
}
}
However, while I can successfully call both DataInput and Ajax methods from an HTML anchor tag, calling them from the XMLHttpRequest object isn't working. Can anyone help me identify the issue?