javascript - Adding rows based on the received json response -


i can enter more 1 student details mentioned in below piece of code clicking + symbol next each row , bin symbol delete if not required :

<tr class="firstclass" id="school0">     <td ><input type="text" id="rollnum" name="rollnum" class="rollclass" maxlength="20"/></td>     <td ><select id="school" name="school" multiple="multiple" style="width: 95px; size: 50px" size="3" class="schoolclass"></td>     <td><img src="<c:url value="/images/add_small.png"/>" id="btnadd1" class="addimg"/></td>     <td><img src="images/delete_small.png" id="btndelete1" class="delimg"/></td > </tr>  <tr class="secondclass" id="college0">     <td ><input type="text" id="rollnum" name="rollnum" class="rollclass" maxlength="20"/></td>     <td ><select id="college" name="college" multiple="multiple" style="width: 95px; size: 50px" size="3" class="schoolclass"></td>     <td><img src="<c:url value="/images/add_small.png"/>" id="btnadd1" class="addimg"/></td>     <td><img src="images/delete_small.png" id="btndelete1" class="delimg"/></td > </tr> 

but tricky part how show them if had received more 1 rows of data json string .

$.ajax({     datatype: "json",     type: "post",     url: 'get_studentlist',     async: false,     data: {         schrollnum: schrollnum,         school: school,         colrollnum: collrollnum,         college: college     },     success: function(response) {         // no clue if had received around 10 rows of data      } 

everything in jquery

you can example , suggest add breakpoint inside success call in chrome check response data or can use network tab see response before write code. code depends on response json structure check network tab in chrome developer tools see response json structure.

$.ajax({     datatype : "json",     type : "post",     url : 'get_studentlist',     async : false,     data : {     schrollnum: schrollnum,     school: school,     colrollnum: collrollnum,     college: college     },      success : function(response) {          //open website in chrome , breakpoint @ line , can play response data in developer console          //if response in json format can directly check          if(response.students && response.students.length){               //insert elements dom data received          }          //if response in string format need parse          var studentdata = json.parse(response);          if(studentdata.students && studentdata.students.length){               //insert elements dom data received          }     } }); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -