I have this code setup in a web page.
<div id="gridResults">
</div>
<script type="text/ecmascript">
jQuery.ajax({
url: "http://localhost:6002/AggregateServices.svc/incident/10",
type: "POST",
async: true,
success:
function(json) {
var table = jQuery('<table />').attr('cellspacing', 0).attr('cellpadding', 4);
var header = jQuery('<tr />')
.append('<td>Case Number</td>')
.append('<td>Company</td>')
.append('<td>Created</td>')
.append('<td>Description</td>')
.append('<td>Stamp</td>')
.append('<td>Status</td>')
.append('<td>Type</td>');
table.append(header);
var row = jQuery('<tr/>')
.append('<td>' + json.CaseNumber + '</td>')
.append('<td>' + json.Company + '</td>')
.append('<td>' + json.Created + '</td>')
.append('<td>' + json.Description + '</td>')
.append('<td>' + json.Stamp + '</td>')
.append('<td>' + json.Status + '</td>')
.append('<td>' + json.Type + '</td>');
table.append(row);
jQuery('#gridResults').append(table).show();
},
error: function() { alert('An error occurred!'); }
});
</script>
When I run the code I end up with this result.
Simple AJAX Sample with jQuery.
Case Number Company Created Description Stamp Status Type undefined undefined undefined undefined undefined undefined undefined
I checked via Fiddler 2, using POST, to make sure I was getting something back. The results I see coming back with Fiddler are as follows:
{"CaseNumber":"2","Company":"company","Created":"9\/1\/2010 6:31:45 PM","Description":"Some description goes here.","Stamp":"\/Date(-62135568000000-0800)\/","Status":"Stat","Type":"Type"}
So that looks like good JSON? Anyone have any idea why this isn't parsing? Or am I missing something else?
TROUBLESHOOTING SO FAR:
I tried to put the row into an append loop, thinking... not sure what I was thinking, but it didn't help anyway. What I did was this, the only difference is that it doesn't even give me the "undefined" as I got in the first sample results.
jQuery.each(json, function() {
var row = jQuery('<tr/>')
.append('<td>' + this.CaseNumber + '</td>')
.append('<td>' + this.Company + '</td>')
.append('<td>' + this.Created + '</td>')
.append('<td>' + this.Description + '</td>')
.append('<td>' + this.Stamp + '</td>')
.append('<td>' + this.Status + '</td>')
.append('<td>' + this.Type + '</td>');
table.append(row);});