0

I am trying to retrieve list . I used below code

 $http({
        method: 'GET',
        url: _spPageContextInfo.webAbsoluteUrl + "/Lists/MyList",
        headers: { "Accept": "application/json;odata=verbose" }
    }).success(function (data, status, headers, config) {
        debugger;
        $scope.customers = data.d.results;
    }).error(function (data, status, headers, config) {

    });

But when code executes i get wiered data in data variable. I get information of whole page which is all html. What am i doing wrong?

  • I am getting the below error. can some one help me. Error: $injector:modulerr Module Error – Harsha Cherukuri Aug 8 '18 at 10:32
5

That is because you are not calling the REST api "/_api/web/lists/getByTitle('MyList')", the url you are calling returns the the ListView (AllItems.aspx) page. Change the url to _spPageContextInfo.webAbsoluteUrl + '/_api/web/lists/getByTitle("MyList")/items'

  • ok now i am not getting wiered data. But i get undefined when i do data.d.results – Happy Sep 9 '15 at 8:42
  • are you trying to load list items or list properties? the endpoint for listitems is "_spPageContextInfo.webAbsoluteUrl + '/_api/web/lists/getByTitle("MyList")/items – sekhar Sep 9 '15 at 8:43
  • just a last question. What if i wanted to retrieve item based on some criteria? – Happy Sep 9 '15 at 8:53
  • you can use the $filter url parameters to filter the data based on a condition(similar to CAML conditions), there are many parameters you can use with REST, here are the operators and usage. msdn.microsoft.com/en-us/library/office/fp142385.aspx and adicodes.com/… – sekhar Sep 9 '15 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.