我在chrome和FF上都遇到了这个错误。
Resource interpreted as Image but transferred with MIME type text/html: "https://www.flickr.com/photos/72731305@N05/13905906938/".
我似乎无法弄清楚我做错了什么。我在stackoverflow上找到的答案告诉我,我需要更改服务器响应...我无法访问它。
我在本地尝试并在我的域名上遇到了同样的错误。
我的代码:
(function(){
var flickr = (function(){
var API_KEY = 'xxxxxxxxxxxxxxxx';
var appendElements = function(dataSet){
var photoSet = document.getElementsByClassName('content')[0];
//var set= document.createTextNode('<img src="'+dataSet[0].id+'" />');
var d;
for (var i = 0;i<dataSet.length;i++){
d = document.createElement('img');
d.src= 'https://www.flickr.com/photos/'+dataSet[i].owner+'/'+dataSet[i].id+'/';
photoSet.appendChild(d);
}
}
return {
getPhotos: function(searchQuery){
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key='+ API_KEY+'&text='+searchQuery+'&format=json&nojsoncallback=1&per_page=15',
xmlhttp = new XMLHttpRequest();
xmlhttp.setRequestHeader("Content-Type","image/jpeg");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var response = JSON.parse(xmlhttp.responseText).photos.photo;
appendElements(response);
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
})();
var input = document.getElementById('test');
input.addEventListener("submit",function(event){
flickr.getPhotos(this.getElementsByTagName('input')[0].value);
event.preventDefault();
},false);
})();
提前致谢。