Created
December 30, 2011 23:32
-
-
Save mark-cooper/1542019 to your computer and use it in GitHub Desktop.
ContentDM API requests using Javascript/JQuery
This file contains hidden or 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
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it is sad to learn that contentdm does not support JSONP.