I'm trying to get put some data into a div which is retrieved from a JSON request via ajax and jQuery:-
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'getTransactions.php?SessionID=53&AccountID=45565',
dataType: 'json',
success: function(retHtml, textStatus) {
var obj = jQuery.parseJSON(retHtml);
$.each(obj, function(AccountID, transactionID, Date, transaction, Status, Amount, CountOfMemo) {
$('#divTransactions').append(AccountID + '<br/>');
$('#divTransactions').append(transactionID + '<br/>');
$('#divTransactions').append(Date + '<br/>');
$('#divTransactions').append(transaction + '<br/>');
$('#divTransactions').append(Status + '<br/>');
$('#divTransactions').append(Amount + '<br/>');
$('#divTransactions').append(CountOfMemo + '<br/><hr/>');
});
},
error: function (xhr, textStatus, errorThrown) {
alert(xhr + "\n" + textStatus + "\n" + errorThrown);
}
});
});
Select all Open in new window
When I look at retHtml it seems to have pulled the JSON array back, however when the debugger tries to run 'var obj = jQuery.parseJSON(retHtml);
' I get
Error: Unable to get property 'length' of undefined or null reference
The page which returns the JSON request (getTransactions.php) gives:-
[
{"AccountID":"66dcf4ef-4c8 b-11e2-aa2 3-18037367 6ac7","tra nsactionID ":"39528e3 4-4c8b-11e 2-aa23-180 373676ac7" ,"Date":"2 012-12-24 00:00:00","transaction":"B ILL PAYMENT","Status":"Cleared ","Amount" :"-350.07" ,"CountOfM emo":"0"},
{"AccountID":"66dcf4ef-4c8 b-11e2-aa2 3-18037367 6ac7","tra nsactionID ":"39528e3 a-4c8b-11e 2-aa23-180 373676ac7" ,"Date":"2 012-12-22 00:00:00","transaction":"C ARD PAYMENT","Status":"Cleared ","Amount" :"-6.33"," CountOfMem o":"0"},
{"AccountID":"66dcf4ef-4c8 b-11e2-aa2 3-18037367 6ac7","tra nsactionID ":"39528e3 5-4c8b-11e 2-aa23-180 373676ac7" ,"Date":"2 012-12-22 00:00:00","transaction":"C ARD PAYMENT","Status":"Cleared ","Amount" :"-50.97", "CountOfMe mo":"0"}
]
Everything looks fine, I just cant get retHtml to get into an array correctly.
Any ideas what Im doing wrong?