0

As you will notice with my code below I'm returning data using responseText. I want to return it as XML data:

//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();

}

The value that is returned and displayed on the page is something like:

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

I need to be able to use this to extract the photo info to construct an image URL to be displayed on screen. But to my understanding I would need to return the value using responseXML rather than responseText.

I have tried responseXML but it gives me back null.

Anon Omus
  • 383
  • 4
  • 12
  • 25
  • 1
    That response is JSON - or better, [JSONP](http://en.wikipedia.org/wiki/JSONP). Of course `responseXML` is `null`, since it's not a valid XML. Why do you want a XML instead? – MaxArt Apr 26 '14 at 22:53
  • Further to what MaxArt said, I believe Flickr does support XML format request and response, but using XML from JavaScript is just making things difficult for yourself even without the problems of a cross-domain request. You're better off sticking with JSONP - which you wouldn't access via a standard Ajax request: see [this question](http://stackoverflow.com/questions/6132796/how-to-make-a-jsonp-request-from-javascript-without-jquery). – nnnnnn Apr 26 '14 at 23:03
  • How can I access the JSON reply in a function through a call back ? I need to have access to it in order to retrieve the values and form images. – Anon Omus Apr 27 '14 at 00:57
  • Read the question I linked to, particularly [this answer](http://stackoverflow.com/a/6132828/615754). JSONP isn't actually Ajax at all, but it gets you a similar result with _less complicated_ JavaScript. – nnnnnn Apr 27 '14 at 02:03

0 Answers0