We help IT Professionals succeed at work.
Get Started

REST API - 'results' undefined

1,375 Views
Last Modified: 2015-04-21
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
Comment
Watch Question
Cloud Expert
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE