• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Ajax in Spring MVC

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello can any one provide me a simple code to returning a list form controller and displaying it on jsp page using ajax

my searchuser.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">

function doAjaxPost() {
$.ajax({
type:"POST",
url: "searchuser1",
cache:false,
data: 'search=' + $("#search").val() ,
success: function(response){
// we have the response
$('#info').html("");
var obj = JSON.parse(response);
$('#info').html(obj);
},
error: function(e){

alert('Error: ' + e);

}

});

}

</script>
<form name="search" method="post">
<input type="text" id="search" name="search">
<br>
<input type="submit" value="submit" onclick="doAjaxPost()">
</form>
<div id="info" style="color: green;">
</div>
</body>
</html>


And in my controller i wrote


@RequestMapping(value="/searchuser", method=RequestMethod.GET)
public String search()
{

return "searchuser";
}
@RequestMapping(value="/searchuser",method=RequestMethod.POST)
public @ResponseBody Vector searchuser(HttpServletRequest request, HttpServletResponse response)
throws Exception
{

String user=request.getParameter("search");
Vector v= UserInterface.accessmodules(user);
return v;
}

but it is giving an error 406

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

please help me


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic