Monday, 19 August 2013

Inserting new row in table from Ajax dynamically

Inserting new row in table from Ajax dynamically

I am getting json string from the web service and want display that in
html page. I have used ajax for dynamically displaying the row in the
table. But the problem is all record are present in the single row.
Code:
function showall(){
var user = document.getElementById("user_name").value;
alert(user);
var row = $("<tr>");
var nextrow = $("</tr>");
$.ajax({
type: "POST",
url: "webresources/hello/showrequests",
data : user,
success : function(data){
console.log(data);
$.each(data, function(index, store){
$.each(store, function(key,value){
row.append($("<td>").html(value));
});
$('#requests').append(row);
$('#requests').append(nextrow);
});
},
error: function(e){
alert("error"+e+"has occured");
}
});
}
output comes like
col11 | col12 | col13 | col21 | col22 | col23|
And i am expecting like
col11 | col12 | col13 |
col21 | col22 | col23|
What I need to do in ajax more? Thank you

No comments:

Post a Comment