正如您将注意到我的代码,我将使用responseText返回数据。我想将其作为XML数据返回:
//Request is a flickr URL with user entered search terms:
function sendRequest (request) {
x = new XMLHttpRequest();
x.open("GET", request,true);
x.onreadystatechange = function () {
if (x.readyState==4 && x.status==200){
//The data is returned as text and added to the page:
document.getElementById("resultsContainer").innerHTML="success: Raw JSON data below <br> <br>"+x.responseText;
document.getElementById("getIms").value = "Find Images";
document.getElementById("getIms").style.background="white";
} else if (x.status == 404){
document.getElementById("resultsContainer").innerHTML="Not Found";
}
}
x.send();
}
页面上返回并显示的值类似于:
jsonFlickrApi({"photos":{"page":1,"pages":476982,"perpage":1,"total":"476982","photo":[{"id":"14021160561","owner":"91285504@N05","secret":"dd4f545e17","server":"2920","farm":3,"title":"barack-obama-painting","ispublic":1,"isfriend":0,"isfamily":0}]},"stat":"ok"})
我需要能够使用它来提取照片信息以构建要在屏幕上显示的图像URL。但根据我的理解,我需要使用responseXML而不是responseText来返回值。
我尝试过responseXML,但它让我回来了。