-2

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.

3
  • 1
    Change URL /_api/Web/Lists/getByTitle('Contacts')/items Commented Dec 15, 2014 at 23:07
  • Please add it as answer so I could mark it. Commented Dec 15, 2014 at 23:23
  • Richard: Posted as answer. Commented Dec 16, 2014 at 0:01

1 Answer 1

1

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

/_api/Web/Lists/getByTitle('Contacts')/items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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