0
votes

I'm creating a travel app in sharepoint 2013 (sharepoint-hosted app) from visual studio and deploying it on office 365. I have created a custom list on office 365 and am trying to access it on office 365 from jquery ajax with the following code

but I get system.unauthorizedAccessException you do not have permission to perform this action

this is my code

    var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
    var listName = "TestList";


   $.ajax(
              {
                  url: siteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
                  type: "GET",
                  headers: {
                      "accept": "application/json;odata=verbose",
                  },
                  success: function (data) {
                      alert("Success");
                  },
                  error: function (err) {
                      alert(JSON.stringify(err));
                  }
              }
          );
1

1 Answers

0
votes

You cannot use plain jQuery Ajax. You need to use the Cross Domain client library as in the below article on MSDN

https://msdn.microsoft.com/en-us/library/office/fp179927.aspx

Also, remember to grant your app the needed permissions against the host web