SharePoint Property Bag allows to store configurations settings at different levels of the SharePoint hierarchy outside of the application itself. Property bag is basically a hash table of key-value pair options.
I'll show how to use Property Bag of a SPWeb object.
First of all you have to be sure that sp.js script is loaded. Usually SP.SOD.executeOrDelayUntilScriptLoadedis used to execute custom code after script is loaded. But sometimes (I don't really know why) it doesn't work. That's why you can insert a call of SP.SOD.executeFunc fucntion before executeOrDelayUntilScriptLoaded. And that will work in any case:
After the script is loaded you can access currentContext object and get web to work with:
Actually you have no web object before you call load and executeQueryAsync functions of currentContext instance (you can read msdn post for clarification). The first parameter of load function is an object that contains the properties to retrieve from the server. Other parameters are optional and contain names of additional properties you want to retrieve. In our case you need to get AllProperties property from the server:
Actually, AllProperties client object is a wrapping-object. That's why you need to call internal function to get key-value pairs of the Property Bag:
To set some property to the Property Bag you should write something like that:
value should be a string. Use JSON.stringify() to convert json object to string and store it to the Property Bag (you can than use JSON.parse() to restore the object). Full test code looks like that:
I'll be glad to have comments and feedback. Have fun!