xhr响应:连接已关闭

时间:2012-06-08 21:21:03

标签: javascript ajax json xmlhttprequest jsonp

我写了一个Flickr搜索引擎,根据选定的下拉框调用公共提要或FlickrApi。 返回的JSONP函数调用的示例:

a)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)中,两者都运行正常,但是当我在上面的域中托管完全相同的代码时,我得到了图像,然后是{{ 1}}不起作用。我注意到(通过查看Firebug)对于jsonFlickrApi响应标题jsonFlickrApi

此外,当我向Connection close

提交请求时,Firebug不会向我显示Response标签

这是代码:

jsonFlickrApi

电话示例:

a)

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);
    }
}

b)

http://flickr.com/services/rest/?method=flickr.photos.search&api_key=75564008a468bf8a284dc94bbd176dd8&tags=red&content_type=1&is_getty=true&text=red&format=json&timestamp=1339189838017

问题:为什么我的连接关闭?为什么它在localhost而不是在实际域上?