Getting different data in ajax response from second time

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+'&nbsp;'+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.

enter image description here

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

enter image description here

I do not understand what is going wrong.

enter image description here

  @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

+4
source share
1 answer

You might want to check if your method has NumberFormatException or SignInNotFoundException , in which case it returns null. The network log shows that 0 bytes of data have been transmitted.

-1
source

All Articles