i working on ajax request/response update table,
but when ajax put call controller getting whole page in response. want precise table data need map c:foreach table. thanks.
jsp view:
<script type="text/javascript"> jquery(document).ready(function(){ function doajaxpost() { // form values var contextpath ='<jsp:expression>contextpath</jsp:expression>'; $.ajax({ type: "get", url: contextpath+"/noticesajaxrequest", datatype: "json", contenttype: 'application/json', success: function(data){ // have response $('#info').empty().html(data); }, }); } setinterval(doajaxpost,10*1000); }); </script> <div id="info"> <c:foreach items="${noticeform.noticelist}" var="notice"> <c:out value="${notice.corevalue} "/> <c:out value="${notice.description} "/> <br/> </c:foreach> </div>
controller:
@controller public class dashboardcontroller { private noticebo noticebo; /*@requestmapping("/dashboardtest") public string printwelcome(modelmap model) { list<employee> employeelist=dashboarddao.getallemployee(); for(employee employee:employeelist) model.addattribute("msg", model.get("msg")+"<br/> spring 3 mvc hello world"+employee.getcustomerid()); return "dashboardtest"; }*/ public noticebo getnoticebo() { return noticebo; } public void setnoticebo(noticebo noticebo) { this.noticebo = noticebo; } @requestmapping("/dashboard") public string dashboard(modelmap model) { return "dashboard"; } @requestmapping("/notices") public modelandview notices(@modelattribute("noticeform") noticeform noticeform, modelmap model) { noticebo.preparenoticelist(noticeform,model); return new modelandview("notices","noticeform",noticeform); } @requestmapping("/noticesajaxrequest") public modelandview noticesajaxrequest(@modelattribute("noticeform") noticeform noticeform, modelmap model) { noticebo.preparenoticelist(noticeform,model); return new modelandview("notices", "noticeform", noticeform); } }
update{1}:
i tried change in controller , starts giving me error: [object xmlhttprequest]
@requestmapping("/noticesajaxrequest") public @responsebody list<notice> noticesajaxrequest(@modelattribute("noticeform") noticeform noticeform, modelmap model) { noticebo.preparenoticelist(noticeform,model); return noticeform.getnoticelist(); }
error description:
http status 406-the resource identified request capable of generating responses characteristics not acceptable according request "accept" headers.
response headers
content-length 1067 content-type text/html;charset=utf-8 date thu, 11 jul 2013 12:48:19 gmt server apache-coyote/1.1
request headers
accept application/json, text/javascript, */* accept-encoding gzip, deflate accept-language en-us,en;q=0.5 cookie jsessionid=d54d66f6b7fe05c2b6fb684bf19387f1 host localhost:8080 referer http://localhost:8080/vservfinance/notices user-agent mozilla/5.0 (windows nt 6.1; wow64; rv:19.0) gecko/20100101 firefox/19.0 x-requested-with xmlhttprequest
thank friends help. best , easy 1 create separate jsp view , include while returning/responding controller.
jquery(document).ready(function(){ function doajaxpost() { // form values var contextpath ='<jsp:expression>contextpath</jsp:expression>'; $.ajax({ type: "get", url: contextpath+"/noticesajaxrequest", success: function(data){ // have response $('#info').html(data); /* $('#info').refresh(); */ }, error: function(e){ alert('error: ' + e); } }); } setinterval(doajaxpost,10*1000); });
controller:
@requestmapping(value="/noticesajaxrequest") public modelandview noticesajaxrequest(@modelattribute("noticeform") noticeform noticeform, modelmap model) { noticebo.preparenoticelist(noticeform,model); return new modelandview("/noticeslist","noticeform",noticeform); }
Comments
Post a Comment