0

I am using YQL and the results are being returned in XML, I have not opted for Json, this Time since I need to emit the exact html under the Results tag of YQL. So i give a call to $.Ajax and get the xml and find the "results" node in the xml.

when i do an alert or appending to a div or a body of html, somehow it seems the whole of Div's and Table's and Td's and Tr's are getting ripped before rendering. I did an alert still didn't see the full raw html.

 $("#result").html("<i>Loading...</i>");
            $.ajax({
                type: "GET",
                url: yql,
                dataType: "xml",
                success: function (xml) {
                    info = $(xml).find('results');
                    alert(info.text());
                    $("body").html(info.text());
                }

What am i missing over here. CDATA for covering html inside xml is not an option over here, just trying to render what is being served from YQL.

Thanks

Rahul
  • 95
  • 1
  • 2
  • 13

1 Answers1

1

I just ran into this problem, and dug up a couple of solutions. The first and easiest would be to do this:

$("#result").html("<i>Loading...</i>");
        $.ajax({
            type: "GET",
            url: yql,
            dataType: "html",
            success: function (xml) {
                info = $(xml).find('results').html();
                alert(info);
                $("body").html(info);
            }

You can find that here (check in the response to the answer): How to use jquery get content with tags in xml

The second solution that worked for me was best explained here: Getting HTML from XML with JavaScript/jQuery

Community
  • 1
  • 1
schadeck
  • 325
  • 2
  • 8
  • 1
    I got my stuff working by doing this way. $(document).ready(function () { $('#result').html("Loading..."); var yql = 'http://query.yahooapis.com/v1/public/yql/...?format=xml&callback=?'; $.getJSON(yql, function (data) { if (data.results[0]) { var data = data.results[0]; $('#result').html(data); } else { var errormsg = '

    Error: could not load the page.

    '; $('#result').html(errormsg); } });
    – Rahul May 14 '12 at 22:59