Created
March 12, 2015 14:26
-
-
Save rheid/816b6ee1af7d65c9da01 to your computer and use it in GitHub Desktop.
Init SharePoint RequestExecutor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
var hostweburl; | |
var appweburl; | |
//Get the URI decoded URLs. | |
hostweburl = decodeURIComponent( getQueryStringParameter("SPHostUrl") ); | |
appweburl = decodeURIComponent( getQueryStringParameter("SPAppWebUrl") ); | |
// Load the .js files using jQuery's getScript function. | |
$.getScript( | |
hostweburl + "/_layouts/15/SP.RequestExecutor.js", | |
continueExecution | |
); | |
// After the cross-domain library is loaded, execution | |
// continues to this function. | |
function continueExecution() { | |
var executor; | |
// Initialize your RequestExecutor object. | |
executor = new SP.RequestExecutor(appweburl); | |
// You can issue requests here using the executeAsync method | |
// of the RequestExecutor object. | |
} | |
// Function to retrieve a query string value. | |
function getQueryStringParameter(paramToRetrieve) { | |
var params = document.URL.split("?")[1].split("&"); | |
var strParams = ""; | |
for (var i = 0; i < params.length; i = i + 1) { | |
var singleParam = params[i].split("="); | |
if (singleParam[0] == paramToRetrieve) | |
return singleParam[1]; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment