I am trying to retrieve the value sent by a controller.I am unable to find the mistake.
$(document).ready(function(){
$("#name").val("welcome");
$("button").click(function(){
var n = $("#name").val();
$.ajax({
type:"post",
url:"${pageContext.request.contextPath}/direct",
data:{name : n},
success:function(data){
$(".display_area").html(data);
alert("coming value = " + data);
},
error:function()
{
alert("Error ");
}
});
});
})
This is my controller. I have tried returning name of a view, tried returning map.
@RequestMapping(value = "/direct", method = RequestMethod.POST)
public String direct(HttpServletRequest request,HttpServletResponse
response) {
String fullname=request.getParameter("name");
System.out.println("hehjgeuqg;qg; "+fullname);
Map<String, String> loPageFields = new HashMap<String, String>();
loPageFields.put("status", fullname);
String fname=loPageFields.get("status");
System.out.println(fname);
return loPageFields.get("status");
}
What I have tried:
I have tried returning a view, map and a string from the controller.
Whenever I return a view whole code of that particular view is being displayed in the display_area div tag. Whenever i tried returning String it enters success block but just displays the alert as "coming value= ".