apijquerytwitpic

not getting xml from API call


I want to make a call to API and get the result in XML format My current code is as below. When I direct provide the XML file then my code runs as expected but when I mention API url to get the same xml then there is no error but call to API is not happening.

I want to do it using AJAX my current code is as below:

<script type="text/javascript">
var searchq = $("#txtTag").val();
var twitpicURL = 'http://twitpic.com/show/thumb/';
$(document).ready(function () {
    $("#btnGetData").click(function () {
        $.ajax({
            type: "GET",
            /* define url of xml file to parse */
            //url: "show.xml",
            url: "http://api.twitpic.com/2/tags/show.xml?tag=" + searchq,
            dataType: "xml",
            success: parseXml
        });
    });

    function parseXml(xml)
    /* this is where the xml file is parsed and converted into a HTML output */
    {
        alert(xml);
        //for each item node in the xml file
        var html = '';
        $(xml).find("image").each(function () {
            var imageId = $(this).find("short_id").text();
            var imagesrc = twitpicURL + imageId;

            html += '<tr class="menu_item">';
            html += '<td class="h-menu">' + "<img src='" + imagesrc + "'/>" + '</td>';
            html += '<td class="h-menu">';
            html += '<div>' + $(this).find("id").text() + '</div>';
            html += '<div>' + $(this).find("short_id").text() + '</div>';
            html += '<div>' + $(this).find("type").text() + '</div>';
            html += '<div>' + $(this).find("timestamp").text() + '</div>';
            html += '<div>' + $(this).find("message").text() + '</div>';
            html += '</td>';
            html += '</tr>';

        });
        $('#tblTwitpic').append($(html));
        //end for each 
        //end function
    }
    //$("#tweets").append("</table>");
});

And my HTML looks like below:

<body>
<input id="btnGetData" type="button" value="Twitter Get Tweets" />
<input type="text" id="txtTag" />
<div id="tweets">
<table id="tblTwitpic" border='1'></table>
</div>

I am not getting any error but the call to this API is not happening.

Thanks in Advance; Abhishek A. Sharma


Solution

  • url: "http://api.twitpic.com/2/tags/show.xml?tag=" + searchq,
    

    Just changed the output from .xml to jsonp. still I dont know why this is not parsing xml oject.