mahaq
asked on
Formatting JSON output into a tabular grid
$.ajax({
type: 'post',
url: something.do,
data: $('#someForm').serialize() ,
success: function(jsonResponse) {
if(jsonResponse.errorMap != null) {
alert(jsonResponse.errorMa p);
} else if (jsonResponse.transactionP age != null) {
showData(jsonResponse.tran sactionPag e); // instead of this I want it to loop and iterate and paint data as given below...
}
}
});
This showData method gets me unformatted data. I want to format it in a tabular grid in a modal window (JSP).
This is the data that is getting returned
{
"transactions":
[
{
"error": "",
"ctrNum1": "123456789",
"successful": true
},
{
"error": "",
"ctrNum2": "123456791",
"successful": true
},
{
"error": "",
"ctrNum3": "123456792",
"successful": true
},
{
"error": "",
"ctrNum4": "123456793",
"successful": true
}
]
}
Also I need iterate or loop in dynamically.
I want to paint the data in a tabular format upon success.
success: function(jsonResponse) {
if(jsonResponse.errorMap != null){
alert(jsonResponse.errorMa p);
}else if(jsonResponse.transactio nSummary != null){
var trans = jsonResponse.transactionSu mmary;
var date = json.transactionDate;
var html = "";
alert(jsonResponse.transac tionSummar y);
alert(jsonResponse.transac tionSummar y.ctrNum);
for (var i=0; i < trans.length; i++) {
html += "<div><div>" + (i + 1) + "</div><div>" + trans.ctrNum + "</div>";
if (trans.successful == true) {
html += "<div>Successful</div></di v>"
} else {
html += "<div>" + trans.error + "</div></div>"
}
}
//showData(jsonResponse.tr ansactionS ummary);
}
}
type: 'post',
url: something.do,
data: $('#someForm').serialize()
success: function(jsonResponse) {
if(jsonResponse.errorMap != null) {
alert(jsonResponse.errorMa
} else if (jsonResponse.transactionP
showData(jsonResponse.tran
}
}
});
This showData method gets me unformatted data. I want to format it in a tabular grid in a modal window (JSP).
This is the data that is getting returned
{
"transactions":
[
{
"error": "",
"ctrNum1": "123456789",
"successful": true
},
{
"error": "",
"ctrNum2": "123456791",
"successful": true
},
{
"error": "",
"ctrNum3": "123456792",
"successful": true
},
{
"error": "",
"ctrNum4": "123456793",
"successful": true
}
]
}
Also I need iterate or loop in dynamically.
I want to paint the data in a tabular format upon success.
success: function(jsonResponse) {
if(jsonResponse.errorMap != null){
alert(jsonResponse.errorMa
}else if(jsonResponse.transactio
var trans = jsonResponse.transactionSu
var date = json.transactionDate;
var html = "";
alert(jsonResponse.transac
alert(jsonResponse.transac
for (var i=0; i < trans.length; i++) {
html += "<div><div>" + (i + 1) + "</div><div>" + trans.ctrNum + "</div>";
if (trans.successful == true) {
html += "<div>Successful</div></di
} else {
html += "<div>" + trans.error + "</div></div>"
}
}
//showData(jsonResponse.tr
}
}
I don't quite see how Java would help. This is a purely Javascript question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The way EE works is that experts take the time to help you out, and you work with them to get an answer that works for you. If you don't respond when you have more questions, and then delete the question without assigning points to the expert after getting help, that isn't respectful of the people you have asked to help you.
tagit gave you an excellent answer. Points should be awarded to him.
tagit gave you an excellent answer. Points should be awarded to him.
ASKER
Hi mrcoffee365,
Sorry for the confusion, but I gave 500 points to tagit.
I had no intention of over looking at it.
Once if any one of you feels I caused any disrespect, sorry about it.
Sorry for the confusion, but I gave 500 points to tagit.
I had no intention of over looking at it.
Once if any one of you feels I caused any disrespect, sorry about it.