我正在为我工作的博物馆写一个小型实用工具。丹麦文化部有一个数据库REGIN,在那里我可以访问有关JSON博物馆项目的各种信息。它是跨域的,没有回调。现在,有一个用于访问数据的API,我想出了如何访问数据库的项目部分,因此我可以选择有关特定博物馆项目的信息。
这是我的问题:这些项目被安排在各种“视图列表”或“集合”中,它们被放在别处。我应该能够访问与我博物馆相关的所有“馆藏”的JSON列表,其ID为229。 网址为https://www.kulturarv.dk/regin/dapi/ListView?&viewType=viewList&format=json&museumId=229 当我在浏览器中正常访问它时,肯定有关于JSON中博物馆“视图”的相关信息。
[
{ "viewId" : "778","OprettetAfId" : "6813","OprettetDato" : "2011-06-20","name" : "Sølv test","keyword" : "test","text" : "Test af genstand for "skab 8"","museumId" : "229" },
{ "viewId" : "779","OprettetAfId" : "6813","OprettetDato" : "2011-06-22","name" : "Rum 29 - Skab 3","keyword" : "Test, drikkekrus, porcelæn","text" : "Genstande til Bibliotekssalens mobil-udstilling, skab 3.","museumId" : "229" },
{ "viewId" : "786","OprettetAfId" : "6813","OprettetDato" : "2011-09-02","name" : "genstand3skab3","keyword" : "til skab 3","text" : "Kærlighedsguden Amor","museumId" : "229" },
{ "viewId" : "792","OprettetAfId" : "6813","OprettetDato" : "2011-10-10","name" : "Skab 3 Bibliotekssalen","keyword" : "Porcelæn","text" : "Skab 3","museumId" : "229" },
{ "viewId" : "793","OprettetAfId" : "6813","OprettetDato" : "2011-10-13","name" : "genstand2skab3","keyword" : "til skab 3","text" : "Fugtbarhedsgudinden Ceres, skab 3","museumId" : "229" }
]
[
{ "viewId" : "778","OprettetAfId" : "6813","OprettetDato" : "2011-06-20","name" : "Sølv test","keyword" : "test","text" : "Test af genstand for "skab 8"","museumId" : "229" },
{ "viewId" : "779","OprettetAfId" : "6813","OprettetDato" : "2011-06-22","name" : "Rum 29 - Skab 3","keyword" : "Test, drikkekrus, porcelæn","text" : "Genstande til Bibliotekssalens mobil-udstilling, skab 3.","museumId" : "229" },
{ "viewId" : "786","OprettetAfId" : "6813","OprettetDato" : "2011-09-02","name" : "genstand3skab3","keyword" : "til skab 3","text" : "Kærlighedsguden Amor","museumId" : "229" },
{ "viewId" : "792","OprettetAfId" : "6813","OprettetDato" : "2011-10-10","name" : "Skab 3 Bibliotekssalen","keyword" : "Porcelæn","text" : "Skab 3","museumId" : "229" },
{ "viewId" : "793","OprettetAfId" : "6813","OprettetDato" : "2011-10-13","name" : "genstand2skab3","keyword" : "til skab 3","text" : "Fugtbarhedsgudinden Ceres, skab 3","museumId" : "229" }
]
现在,由于我不知道的原因,我用来访问特定项目信息的相同程序不允许我打开前面提到的URL。这是我访问上述JSON的代码,它不返回任何内容:
$(document).ready(function() {
xmlhttp = new XSiteHttpRequest(); //a custom XHR... not sure why they decided to do it that way
xmlhttp.open("GET","https://www.kulturarv.dk/regin/dapi/ListView?&viewType=viewList&format=json&museumId=229",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status!=404) {
alert("Works!");
}
else {
alert("Does not work!");
};
};
};
xmlhttp.send(null);
});
现在,我认为因为我没有警报(“工作!”)或警报(“不工作!”)我做错了。
相同的程序适用于此网址: https://www.kulturarv.dk/regin/dapi/ListView?viewType=objectContent&format=xml&objectType=Genstand&objectId=3911238
此代码提供适当的警报:
$(document).ready(function() {
xmlhttp = new XSiteHttpRequest(); //a custom XHR... not sure why they decided to do it that way
xmlhttp.open("GET","https://www.kulturarv.dk/regin/dapi/ListView?&viewType=viewList&format=json&museumId=229",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status!=404) {
alert("Works!");
}
else {
alert("Does not work!");
};
};
};
xmlhttp.send(null);
});
我可以看到两者之间没有区别,所以可能会发生什么?
我通过Firefox运行了非工作代码,错误consol说“未终止字符串文字”。不确定这意味着什么。