Reputation: 5576
The CrossRef Search API (docs here) provides citation information from DOI identifiers. I tried using it to get this info but am oddly getting 404 responses.
The headers I set were
Content-type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 86400
I get the same result from this appspot tester, so I wouldn't think it's my code.
Can anyone advise how I could get it working? It works just fine from their own domain.
It's possible they don't allow cross-domain at all, but I'm not sure if/how I could check that.
Reproducible example:
function doiInfo(doi) {
var doienc = encodeURIComponent(doi);
var doiXHR;
window.XMLHttpRequest ? doiXHR=new XMLHttpRequest() : doiXHR=new ActiveXObject("Microsoft.XMLHTTP");
doiXHR.onreadystatechange=function()
{
if (doiXHR.readyState==4 && doiXHR.status==200)
{
console.log(doiXHR.responseText);
} else if (doiXHR.readyState==4) {
// something went wrong
}
}
doiXHR.open("GET", "http://search.crossref.org/dois?q=" + doienc, true);
doiXHR.setRequestHeader("Content-type", "application/json;");
doiXHR.setRequestHeader("Access-Control-Allow-Origin", "*");
doiXHR.setRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
doiXHR.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
doiXHR.setRequestHeader("Access-Control-Max-Age", "86400"); // cache for 1 day
// doiXHR.withCredentials = "true";
doiXHR.send();
}
doiInfo('10.1002/bies.201000071')
In the browser console from crossref.org
I get
[
{
"doi": "http://dx.doi.org/10.1002/bies.201000071",
"score": 18.623272,
"normalizedScore": 100,
"title": "The phage-host arms race: Shaping the evolution of microbes",
"fullCitation": "Adi Stern, Rotem Sorek, 2010, 'The phage-host arms race: Shaping the evolution of microbes', <i>BioEssays</i>, vol. 33, no. 1, pp. 43-51",
"coins": "ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.1002%2Fbies.201000071&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&rft.atitle=The+phage-host+arms+race%3A+Shaping+the+evolution+of+microbes&rft.jtitle=BioEssays&rft.date=2010&rft.volume=33&rft.issue=1&rft.spage=43&rft.epage=51&rft.aufirst=Adi&rft.aulast=Stern&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.au=Adi+Stern&rft.au=+Rotem+Sorek",
"year": "2010"
}
]
Running it from my website (not https) I get
OPTIONS http://search.crossref.org/dois?q=10.1002%2Fbies.201000071 404 (Not Found) XMLHttpRequest cannot load http://search.crossref.org/dois?q=10.1002%2Fbies.201000071. Invalid HTTP status code 404
The GET
/OPTIONS
issue aside, it definitely seems to get a 404 on the page, which doesn't seem right.
I think you can get around it with an iframe and window.postMessage
(?) but that sounds messy.
Please comment if I can provide more details and I'll be happy to, doesn't seem like anyone's done this before online - hopefully not because it's impossible!
Upvotes: 0
Views: 338
Reputation: 64
Answering the title of your question: yes it allows Cross-Origin requests. A 404 indicates a wrong resource. Cross-origin problems would give you a 401.
The allow-origin header indicates that the resource can be accessed from all locations. Take a look at my working example: http://pastebin.com/8W23P48Z
Upvotes: 1