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
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
</head> | |
<script src="https://code.jquery.com/jquery.js" type="text/javascript"></script> | |
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script> | |
<script type="text/javascript" src="/_layouts/15/sp.js"></script> | |
<script> | |
var hostweburl; | |
var appweburl; | |
$(function () { | |
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl")); | |
appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl")); | |
$("#btnGet").click(function () { | |
getSPList(); | |
getSPListItems(); | |
getSPListItemAttachment(2); | |
}); | |
}); | |
function getSPList() { | |
var getProperty = appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "/RestSubWeb'"; | |
$.ajax({ | |
url: getProperty, | |
type: 'GET', | |
headers: { "accept": "application/json;odata=verbose" }, | |
//success: function (data) { | |
// console.log("done"); | |
// alert(data.d.OData__x005f); | |
// //return data; | |
//}, | |
success: function (result) { | |
var objData = $.parseJSON(result.body); | |
response($.map(objData.d.results, function (item) { | |
return { | |
label: item.Title | |
} | |
})); | |
}, | |
error: function (sender, args) { | |
console.log(args.get_message()); | |
} | |
}); | |
} | |
function getSPListItems() { | |
var getProperty = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Infringements')/items?@target='" + hostweburl + "/RestSubWeb'"; | |
$.ajax({ | |
url: getProperty, | |
type: 'GET', | |
headers: { "accept": "application/json;odata=verbose" }, | |
//success: function (data) { | |
// console.log("done"); | |
// alert(data.d.OData__x005f); | |
// //return data; | |
//}, | |
success: function (result) { | |
var objData = $.parseJSON(result.body); | |
response($.map(objData.d.results, function (item) { | |
return { | |
label: item.Title | |
} | |
})); | |
}, | |
error: function (sender, args) { | |
console.log(args.get_message()); | |
} | |
}); | |
} | |
function getSPListItemAttachment(id) { | |
var getProperty = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Infringements')/items(" + id + ")/AttachmentFiles?@target='" + hostweburl + "/RestSubWeb'"; | |
$.ajax({ | |
url: getProperty, | |
type: 'GET', | |
headers: { "accept": "application/json;odata=verbose" }, | |
success: function (result) { | |
var objData = $.parseJSON(result.body); | |
response($.map(objData.d.results, function (item) { | |
return { | |
label: item.Title | |
} | |
})); | |
}, | |
error: function (sender, args) { | |
console.log(args.get_message()); | |
} | |
}); | |
} | |
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]; | |
} | |
} | |
</script> | |
<body> | |
<input id="btnGet" value="Get" type="button" /> | |
</body> | |
</html> |