Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Last active March 22, 2021 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidGodzilla/72d5059acd7de98fae11b3ea31e8177a to your computer and use it in GitHub Desktop.
Save kidGodzilla/72d5059acd7de98fae11b3ea31e8177a to your computer and use it in GitHub Desktop.
jQuery Automatic Data Fill
/**
* Instant Data for your OCDB Project (requires jQuery)
*
* Just use magic classes or data attributes matching your string data and they'll be automatically filled
*
* Example:
*
* <h1 data-for-h1></h1> <!-- This gets populated with data from the key `h1` -->
*
*/
// Replace this URL with your own
let OCDB_URL = 'https://ocdb-db.patgriffith.com/v1/db/9/gW0D5osEwOXrrdM0lH3oMr5dYHf1Bsnp7OxuLlWE';
$(document).ready(function () {
$.get(OCDB_URL, function (data) {
if (!data || typeof data !== 'object') return;
for (let k in data) {
let item = data[k];
if (item && item.value && typeof item.value === 'string') {
$(`[data-for-${ k }]`).attr('src', item.value);
$(`[data-for-${ k }]`).html(item.value);
$(`.data-for-${ k }`).html(item.value);
}
}
}).fail(function (e) {
console.log(e);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment