1

This thread is very similar to that question but I am not convinced by the answer given ("The library can't be used if the application is not deployed on the same sharepoint site domain") because in this page here the author insists on the fact that it is possible via the object SP.RequestExecutor(appweburl).

So I followed all the steps mentionned in the page and I ended up with this code:

$(document).ready(function () { 
  var hostweburl = decodeURIComponent("https://lpl.sharepoint.com/sites/TestPortail"); 
  var appweburl = decodeURIComponent("http://localhost"); 
  var scriptbase = hostweburl + "/_layouts/15/";

  // Load the .js file using jQuery's getScript function. 
  $.getScript( hostweburl + "/_layouts/15/SP.RequestExecutor.js", continueExecution );

  function continueExecution() { 
      var executor; 

      // Initialize your RequestExecutor object. 
      executor = new SP.RequestExecutor(appweburl); 
      console.log(executor); // just to see if created

      // You can issue requests here using the executeAsync method 
      // of the RequestExecutor object.
      executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web/title?@target='" + hostweburl + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
        console.log('Successfully obtained data.');
      },
      error: function (jqXHR, textStatus, errorThrown) {
        console.log('There is an error.');
        console.log(jqXHR.status);
        console.log(textStatus);
        console.log(errorThrown);
      }
    });
  } 
});

When I executed it from localhost I get this:

enter image description here

I have been looking for the solution for 2 days. Maybe it is because the localhost is not a https, but even with this great answer I have not managed to do it (wamp won't start).

Any help would be appreciated.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Héloïse Chauvel
  • 502
  • 3
  • 6
  • 21

0 Answers0