I ran into a problem that I canβt find out why.
I am using spring mvc and I am sending an ajax request to one of my controllers.
$.get("<c:url value="/createcomment" />", {id: pageid , newcomment : newcomment}) .done(function(data){ $("#newcomment"+data.pageId).val(''); var html = '<tr><td>'+ '<div class="pull-left">'+ '<img class="img-rounded" src="resources/profile-pics/male/small.jpg" alt="">'+ '</div><div class="span4"><ul class="nav nav-stacked">'+ '<li><font size="2"><i class="icon-user"></i>'+data.account.firstName+' '+data.account.lastName+'</font></li>'+ '<li><font size="2">'+data.text+'</font></li><li><font size="1">'+data.postingDate+ '</font></li></ul></div></td></tr>'; $(html).inserAfter($("#tr"+data.pageId)); }
When I refresh the page and submit the request, I get the next desired object.

and when I send it a second time, I will get some document object.

I do not understand what is going wrong.

@RequestMapping(value="/createcomment",method=RequestMethod.GET) public @ResponseBody Comment createComment(@RequestParam(value="id")final String pageId,@RequestParam(value="newcomment")final String text, final HttpServletRequest request ,final WebRequest req){ final Comment comment = new Comment(); comment.setId(GenerateUID.generate()); comment.setText(text); comment.setPostingDate(new Date()); comment.setPageId(Long.valueOf(pageId)); try { return comment; } catch (NumberFormatException e) { return null; } catch (SignInNotFoundException e) { return null; } }
For additional information only, I'm using jQuery JavaScript Library v1.7.1
source share