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> | |
$(function () { | |
$("#btnSet").click(function () { | |
setSPProperty(); | |
}); | |
$("#btnGet").click(function () { | |
getSPProperty(); | |
}); | |
}); | |
function setSPProperty() { | |
var objCtx = new SP.ClientContext.get_current(); | |
var objWeb = objCtx.get_web(); | |
var objAllProps = objWeb.get_allProperties(); | |
objAllProps.set_item("MyPropertyName", value); | |
objWeb.update() | |
objCtx.load(objWeb); | |
objCtx.executeQueryAsync( | |
function () { | |
console.log("done"); | |
}, | |
function (sender, args) { | |
console.log("error"); | |
}); | |
} | |
function getSPProperty() { | |
var getPropertyurl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/AllProperties/?select=" + "MyPropertyName"; | |
$.ajax({ | |
url: getPropertyurl, | |
type: 'GET', | |
headers: { "accept": "application/json;odata=verbose" }, | |
success: function (odata) { | |
console.log("done"); | |
alert(odata.d.OData__x005fMyPropertyName); | |
//return odata; | |
}, | |
error: function (sender, args) { | |
console.log(args.get_message()); | |
} | |
}); | |
} | |
</script> | |
<body> | |
<input id="btnSet" value="Set" type="button" /> | |
<input id="btnGet" value="Get" type="button" /> | |
</body> | |
</html> |