locked
REST results undefined RRS feed

  • Question

  • I am executing this code, but am getting the d.results = undefined:

    'use strict';
    $(function () {
        var call = $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('Contacts')",
            type: "Get",
            dataType: "json",
            headers: {
                Accept: "application/json;odata=verbose"
            }
        });
        call.done(function (data,textStatus,jqXHR) {
            var message = $("#message");
            message.text("There are " + data.d.results.length + " items in this list");
            messa.append("<br/>");
            $.each(data.d.results, function (index, value) {
                message.append(value.Title);
                message.append("<br/>");

            });

        });

        call.fail(function (jqXHR, textStatus, errorThrown) {
            var response = JSON.parse(jqXHR.responseText);
            var message = response ? response.error.message.value : textStatus;
            alert(message);

        });
    });

    Any help is appreciated.

    Thursday, December 18, 2014 12:02 AM

Answers

  • Since you are trying to get items you should change the URL as follows

    /_api/Web/Lists/getByTitle('Contacts')/items
    Thursday, December 18, 2014 5:23 AM

All replies

  • Since you are trying to get items you should change the URL as follows

    /_api/Web/Lists/getByTitle('Contacts')/items
    Thursday, December 18, 2014 5:23 AM
  • Hi

    I am getting the exact some issue with this url

     var urlItemAllFields = appweburl +
                     "/_api/SP.AppContextSite(@target)/web/getfilebyserverrelativeurl('" +     itemurl + "')/ListItemAllFields?@target='" + hostweburl + "'";
    

    I will put this out in new post to see if I get a response ( no pun intended ;-) )

    Daniel


    Freelance consultant

    Friday, February 6, 2015 11:56 AM