javascript - How to pass list of objects from spring mvc to jquery using ajax and json? -


can please suggest me, how pass , display list of objects springmvc jsp page jquery using ajax, jquery , json.

here controller:

@requestmapping(value="/viewuserlist", method=requestmethod.get) public @responsebody list<wizardto> retriveuserlist(@requestparam(value = "role") string role) {         wizarddao dao = new wizarddao();         list<wizardto> userlist= dao.getuserlist(role);         return userlist;         /*string str="returned controller";         return str;*/   // working     } 

and here jquery code (inside jsp file request , response handling )

<script src="http://code.jquery.com/jquery-latest.min.js"></script>     <script >       function doajax(){         alert("in doajax");        // jquery("#list").jqgrid({         $.ajax({                 url: '\viewuserlist',             type: 'get',             data: "role="+ $("#myrole").val(),             datatype: "json",            /*   success:function(list){                 alert("success" +list);             } , */              success: function(data, textstatus, jqxhr) {                  alert("success " +data +textstatus+jqxhr);                  console.log(data.error);                 },          //   error : alert("error"),          error: function(jqxhr, textstatus, errorthrown) {              alert("error "+"jqxhr "+jqxhr+" textstatus "+textstatus+" errorthrown "+errorthrown);              console.log(textstatus, errorthrown);             }    /*          colnames:['userid','firstname', 'lastname', 'role'],              colmodel:[                         {name:'userid',index:'userid', width:55},                         {name:'firstname',index:'firstname', width:100},                         {name:'lastname',index:'lastname', width:100},                         {name:'role',index:'role', width:100},                        ],                  // rownum:10,                   //rowlist:[10,20,30],                   pager: '#userlistdiv',                   sortname: 'id',                   viewrecords: true,                   sortorder: "desc",                   caption:"releted user list",                   editurl:""                  }).navgrid("#userlistdiv",                         {edit:false,add:false,del:false});  */         });     } </script> 

this doajax() method called when click on particular href link,i tried use jquery grid display received object, doing mistakes,

i new in springmvc , jquery;i started working spring-mvc jquery , ajax before days.

i want print table in particular division, tried return string controller jquery , worked dont know how return list of array controller jquery.

can please me issue...?? (and don't want load other jsp page, want load data on same page sending request, in short want of ajax,json , jquery).

there 2 things noticed , commented though:

  1. your ajax's url : "\viewuserlist" not using correct slash \.
  2. you have not posted controller's annotation @controller

so can add these 2 , see if helps:

controller:

@controller @requestmapping(value="/viewuserlist", method=requestmethod.get) 

jquery ajax:

change this:

url: '\viewuserlist', 

to this:

url: '/viewuserlist', 

check see if sorts out.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -