I am trying to create a Sharepoint hosted add-ins to get data list items. My code are below

var hostweburl;
var appweburl;

//The SharePoint site where the App is installed
hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
//The Location within the site where the App will be deployed
appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));

//resources are in URLs in the form: web_url/_layout/15/resource
var scriptbase = hostweburl + "/_layout/15/";
$.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);

//Use cross-domain library to interact with more than one domain
//in your remote add-in page through a proxy
function execCrossDomainRequest() {
    var executor = new SP.RequestExecutor(appweburl);

$("#showButton").click(function () {

    var executor = new SP.RequestExecutor(appweburl);

        url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Ingredients')/Items?@target='" + hostweburl + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: successHandler,
        error: errorHandler

The result after I clicked the button is always null. I already checked in browser that my list is not empty

This is my successHandler code

function successHandler(data) {
var jsonObject = JSON.parse(data.body);
var ingredientsHTML = "";
var results = jsonObject.d.results;

for (var i = 0; i < results.length; i++)
    ingredientsHTML = ingredientsHTML + "<p><h3>" + results[i].Title + "</p><hr>";
document.getElementById("resultsDiv").innerHTML = ingredientsHTML;


  • Can you post the output of this? console.log(appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Ingredients')/Items?@target='" + hostweburl + "'"); and the code of your sucessHandler? – iOnline247 Aug 25 '16 at 4:30

Your Answer

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

Browse other questions tagged or ask your own question.