Search code examples
xmlajaxangularjsjsonp

Cross domain ajax request that returns xml using AngularJS


I am trying to connect to the answerbase api using AngularJs. I got it to return the xml using jsonp but I get a format error. Unfortunately xml is the only format they will return. I have attempted to use the xml2json library with no success. This is what I have so far.

var url = "http://myAnswerBaseSite.com/api/getquestionslist.aspx?apikey=myKey&callback=JSON_CALLBACK";

$http.jsonp(url,
    {
        transformResponse: function (data) {
            var x2js = new X2JS();
            var json = x2js.xml_str2json(data);
            return json;
        }
    })
    .success(function (data) {
        console.log(data.found);
    });

Is this possible? Thanks in advance


Solution

  • Same here. Unfortunately the jsonp function parses the content BEFORE the transform callback. So no, it's not possible.

    You can only change the response to be a JSON or use another method. (Well, you can also wrap the real API on your server and produce the same results in JSON format, building a mirror API service)

    Have a nice day,