• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

JSON array

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);
				}
			});
    	});

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-4c8b-11e2-aa23-180373676ac7","transactionID":"39528e34-4c8b-11e2-aa23-180373676ac7","Date":"2012-12-24 00:00:00","transaction":"BILL PAYMENT","Status":"Cleared","Amount":"-350.07","CountOfMemo":"0"},
{"AccountID":"66dcf4ef-4c8b-11e2-aa23-180373676ac7","transactionID":"39528e3a-4c8b-11e2-aa23-180373676ac7","Date":"2012-12-22 00:00:00","transaction":"CARD PAYMENT","Status":"Cleared","Amount":"-6.33","CountOfMemo":"0"},
{"AccountID":"66dcf4ef-4c8b-11e2-aa23-180373676ac7","transactionID":"39528e35-4c8b-11e2-aa23-180373676ac7","Date":"2012-12-22 00:00:00","transaction":"CARD PAYMENT","Status":"Cleared","Amount":"-50.97","CountOfMemo":"0"}
]

Everything looks fine, I just cant get retHtml to get into an array correctly.

Any ideas what Im doing wrong?
0
tonelm54
Asked:
tonelm54
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
could you provide a link to check ?
0
 
tonelm54Author Commented:
Ive put the code up onto a test site:-

Test Link
0
 
leakim971PluritechnicianCommented:
replace :
$.each(retHtml, function(AccountID, transactionID, Date, transaction, Status, Amount, CountOfMemo) {
                    $('#divTransactions').append(AccountID + '<br/>' + transactionID + '<br/>' + Date + '<br/>' + transaction + '<br/>' + Status + '<br/>' + Amount + '<br/>' + CountOfMemo + '<br/><hr/>');

Open in new window

by :
$.each(retHtml, function(i, v) {
                    $('#divTransactions').append(v.AccountID + '<br/>' + v.transactionID + '<br/>' + v.Date + '<br/>' + v.transaction + '<br/>' + Status + '<br/>' + v.Amount + '<br/>' + v.CountOfMemo + '<br/><hr/>');

Open in new window


http://api.jquery.com/jQuery.each/
0
 
tonelm54Author Commented:
:-)

Thank you
0
 
tonelm54Author Commented:
:-)

Thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now