Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created December 30, 2011 23:32
Show Gist options
  • Save mark-cooper/1542019 to your computer and use it in GitHub Desktop.
Save mark-cooper/1542019 to your computer and use it in GitHub Desktop.
ContentDM API requests using Javascript/JQuery
jQuery(function() {
// Cross Domain Policy restricted (obviously)
$.get('https://server15763.contentdm.oclc.org/dmwebservices/index.php?q=dmGetItemInfo/p15763coll5/149/json', function(data) {
console.log(data);
}, 'json');
// JSONP not supported
$.get('https://server15763.contentdm.oclc.org/dmwebservices/index.php?q=dmGetItemInfo/p15763coll5/149/json', function(data) {
console.log(data);
}, 'jsonp');
// With the addition of jquery.xdomainajax.js this will work
// https://github.com/padolsey/jQuery-Plugins/blob/master/cross-domain-ajax/jquery.xdomainajax.js
$.get('https://server15763.contentdm.oclc.org/dmwebservices/index.php?q=dmGetItemInfo/p15763coll5/149/json', function(data) {
console.log(data); // an HTML string
var start = data.responseText.indexOf("{"); // JSON open
var end = data.responseText.lastIndexOf("}"); // JSON close
var distance = (end - start) + 1;
var json = jQuery.parseJSON(data.responseText.substr(start, distance));
console.log(json);
});
});
@dunglehome
Copy link

it is sad to learn that contentdm does not support JSONP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment