I have an issue I have this jQuery code:
$(document).ready(function(){
$("#follow").click(function(){
$.ajax({
type: 'POST',
url:'/tweety-0.0.1-SNAPSHOT/twitter/tiles/follow',
data:{
searchedUser: $('#searchedUser').val()
}
})
})
})
this piece of code get hidden id and send it’s value to the following method in my controller:
@RequestMapping(value="/follow",method=RequestMethod.POST)
public @ResponseBody void followUser(@RequestParam("searchedUser") String userToFollow,
@ModelAttribute("user") User user) {
if(userToFollow.equals(user.getUsername())){
// do nothing
}else{
service.followUser(userToFollow,user.getUsername());
}
}
I want to send a session scoped attribute through the previous ajax call. Any clue on how doing that??
Your best bet is to have that attribute’s value in a hidden input field somewhere on the page, so you can then read it in with jQuery.
Unforunately, to the best of my knowledge jQuery or javascript does not have access to request, session or application scope variables.
So, if you do something like this:
You can access it after the page loads like this:
This is the solution I’ve used when needing to get tomcat session vars into javascript, the method should work for you too.
Hope this helps