Code and Stuff

Feb 20, 2013

JSONP EPrints

EPrints supports JSON-P. It is therefore possible to include a list of publication with javascript on a different host without the need for the CORS headers.

Here an example using SUPSI's eprints repository. List of publications with creator being david huber:

    Howto

    You will need the url to the JSON export of the desired search. In other words: perform the search, choose to export as JSON and copy the url. In my case the url was:
    http://repository.supsi.ch/cgi/search/archive/advanced/export_SUPSI_Institutional_Repository_JSON.js?screen=Search&dataset=archive&_action_export=1&output=JSON&exp=0%7C1%7C-date%2Fcreators_name%2Ftitle%7Carchive%7C-%7Ccreators_name%3Acreators_name%3AALL%3AEQ%3Adavid+huber%7C-%7Ceprint_status%3Aeprint_status%3AANY%3AEQ%3Aarchive%7Cmetadata_visibility%3Ametadata_visibility%3AANY%3AEQ%3Ashow&n=&cache=

    Append to that url the JSONP part:

    &jsonp=functionName
    Replace functionName with any desired function name. As expected by JSONP, the new URL will return a javascript that can be used with a script tag and will pass to functionName an array of publication objects.
    <script type="text/javascript" src="the JSONP URL"></script>
    
    This script tag can also be injected in the DOM when needed. For instance at DOM ready with the following JQuery code:
    // execute when DOM is ready
    $(function() {
      $(document.body).append("<script type='text/javascript' src='the JSONP URL'></script>");
    });
    

    No comments: