REST API - 'results' undefined

I have a list and when the page loads I want to grab the items from my list and add it to an array. I am getting an error when I try to read the rest data.  Here's what i have so far.

<script>
$(document).ready(function() { 
	var iceCreamApp = {};
	iceCreamApp.Truck = new Array();
	
	//Load data from list into array right away
	(function() {
		var url = "http://isaac.issharepoint.com/demo/_vti_bin/listdata.svc/IceCreamTrucks";
		$.ajax({
			url:url,
			method:"GET",
			headers: {"Accept": "application/json; odata=verbose"},
			success: function(data) {
				success(data.d);
			},
			error: function(data) {
				failure(data.responseJSON.error);
			}
		})
			
			function success(data)
			{
				console.log(data.d.results);
			}
	}());
	
	
})</script>

Open in new window


Here's the error I get
SCRIPT5007: Unable to get property 'results' of undefined or null reference

Points to this line
console.log(data.d.results);
Any help would be great. thanks
LVL 5
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie McAllister MVPSharePoint ConsultantCommented:
It's a little typo I think;

You call Success like this;

success(data.d);

But the signature is this;

function success(data)

So you're effectively calling console.log(data.d.d.results); in your code, hence the null ref.
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Thanks but now I get a blank page.  None of the data is rendering in the console.
Here's the updated code:

(function() {
		var url = "http://isaac.issharepoint.com/demo/_api/web/lists/GetByTitle('IceCreamTrucks')/items?$select=State";
		$.ajax({
			url:url,
			type:"GET",
			dataType:"json",
			headers: {"Accept": "application/json; odata=verbose"},
			success: function(data) {
				success(data);
			},
			error: function(data) {
				//failure(data);
			}
		})
			
			function success(data)
			{
				console.log(data);
			}
	}());

Open in new window

0
Jamie McAllister MVPSharePoint ConsultantCommented:
How do you know it succeeds when the failure call is commented out?

In the Success line why not address a specific property of the returned data for display?

or just try this; alert(data.d);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IsaacSharePoint Client Side DeveloperAuthor Commented:
When I had the failure line uncommented, that's what rendered. I will try data.d
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
That still does not work for me.  Here's the page below.
http://isaac.issharepoint.com/demo/SitePages/iceCream.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Services

From novice to tech pro — start learning today.