Some times you just need a quick and dirty data storage, something that just gives you a bucket to pour some data into.
This is that bucket.
Update the settings file with the values for your enviroment, in that file you'll also find the SQL for creating the database table.
Create/Upload/add/Edit and you'll have your own /b.
Saving is as simple as a GET request to the server. If an ID is supplied
that post will be updated.
Remember that this method limits the amount of data transported to the max URL length, so try to keep it under 1855 characters in total.
function saveData(key, data, id){
var request = {
key: key,
data: JSON.stringify(data)
};
if(id)
request.id = id;
$.getJSON("/b", request)
.fail(function(re){
//Handle failures to save here
})
.done(function(re){
//Handle successful save here
})
}
If the save is successful you will get a JSON object back consisting of these keys:
typeResponse type (ie. "success")infoAction performed (ie. "inserted")idThe ID of the element effected
{
type: "success",
info: "inserted",
id: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr"
}
Loading is just as simple, just supply the key of the bucket and the ID of the data.
function loadData(key, id){
$.getJSON("/b",{
key: key,
id: id
})
.fail(function(re){
//Handle load fail here
})
.done(function(re){
//Handle successful loading here
//Don't forgett to parse it if it's JSON
//i.e. JSON.parse(re)
})
}
Successfully loading data returns these keys:
typeResponse type (ie. "success")infoAction performed (ie. "loaded")idThe ID of the element effecteddataThe data saved (as a string)createdThe time the ID was created
{
type: "success",
info: "loaded",
id: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr",
data: '{"hello":"world"}',
created: "1970-01-01 00:00:00"
}
Not often but sometimes you go goof up, then the server will return an error. This happens when you don't send enough parameters, the wrong parameters or something else is wrong. This is what it can look like:
{
"type":"error",
"info":"wrong parameters"
}
Please note that all errors will be wrapped in a HTTP 500 response.
That's it. ♥