0
我一直在努力尋找flickr搜索一段時間。最初我用PHP檢索XML文件並將其轉換爲simpleXML,但我無法通過Javascript訪問信息來構建指向圖像的鏈接。非常令人沮喪!Flickr使用Javascript以json格式進行圖像檢索
因此,我決定通過放棄PHP和交換到javascript獲取使用json的鏈接來簡化它。
我在將文本輸入到文本框中以填充flickr請求時遇到問題。
當我在此鏈接中手動使用文本字詞時,它將檢索沒有圖像的圖像框。當我點擊圖像框時,Flickr的鏈接工作。
我在做什麼錯了?
任何幫助將非常感謝,因爲我已經嘗試了3-4種不同的方式,現在仍然覺得我無處可去!
感謝 邁克
<script type = "text/javascript">
function jsonFlickrApi(rsp){
window.rsp = rsp;
var display = "";
// loop through the objects to build the images from the json response
for(var i=0; i<rsp.photos.photo.length; i++){
photo = rsp.photos.photo[i];
// use the various elements of the json object to build the link
details_url = "http://farm" +photo.farm+ "static.flickr.com/" +photo.server+ "/" +photo.id+ "_" +photo.secret+ "_" + "t.jpg"; <!-- get
owner_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id;
display += '<a href="' + owner_url + '">' + '<img alt="'+photo.title + '"src="' + details_url + '"/>' + '</a>';
}
// display the images
document.writeln(display);
}
</script>
這是一個Flickr搜索
<!-- the form is supposed to take a request from the user -->
<form id="flickr_form">
<input type="text" name="search" id="search"/>
<input type="submit" value="Search"/>
</form>
<script src = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=0a109e625227a913ef57ac207f1af24f&text="+document.getElementById("search").value+"&per_page=10&format=json">
</script>