我寫了一個Flickr搜索引擎,根據選定的下拉框調用公共提要或FlickrApi。該JSONP函數調用的 例子返回:xhr回覆:連接關閉
一)jsonFlickrApi({"photos":{"page":1, "pages":201, "perpage":100, "total":"20042", "photo":[{"id":"5101738723"...
B)jsonFlickrFeed({ "title": "Recent Uploads tagged red","link": "http://www.flickr.com/photos/tags/red/","description": "", ....
奇怪的是,在我的本地安裝(xampp
)都工作得不錯,我也得到圖片但當我在上述域中託管完全相同的代碼時,jsonFlickrApi
不起作用。我發現(通過看螢火蟲)是爲jsonFlickrApi
響應頭說Connection close
此外,螢火蟲不顯示我Response
選項卡時,我提出請求jsonFlickrApi
這裏是代碼:呼叫
function makeCall(uri)
{
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET", "jsonget.php?url="+uri, true);
xmlhttp.send();
}
function jsonFlickrApi(response)
{
var data= response.photos.photo ;
var output = "";
output += "<img src=http://farm" + data[4].farm + ".static.flickr.com/" + data[1].server + "/" + data[4].id + "_" + data[4].secret + ".jpg>";
document.getElementById("cell-0").innerHTML = output ;
}
//Public Feed
function jsonFlickrFeed(response)
{
var data= response.items[0].media.m ;
alert(data);
var output = "";
output += "<img src=" + data+ ">";
document.getElementById("cell-0").innerHTML = output ;
}
function callback()
{
//console.log("Ready State: " + xmlhttp.readyState + "\nStatus" + xmlhttp.status);
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
var jsonResponse = xmlhttp.responseText;
jsonResponse = eval(jsonResponse);
}
}
例子:
一個)
http://flickr.com/services/rest/?method=flickr.photos.search&api_key=75564008a468bf8a284dc94bbd176dd8&tags=red&content_type=1&is_getty=true&text=red&format=json×tamp=1339189838017
B)
http://api.flickr.com/services/feeds/photos_public.gne?tags=red&format=json×tamp=1339190039407
問:爲什麼我的連接關閉?爲什麼它在localhost上工作,而不是在實際的域上?
謝謝你的幫忙! – raoulbia