Making cross domain call using JSONP (JSON with padding)

Hi,

Just created a simple html page that uses JSONP to make cross domain call to twitter’s API.

Source Code:-

<!DOCTYPE html>
<html>
<head>
    <title>JSONP Example</title>
    <script>

        function getTweets(tweets) {

            var tweetDiv = document.getElementById("tweet");

            for (var i = 0; i < tweets.results.length; i++) {
                var tweet = tweets.results[i];

                // create div element for each result
                var div = document.createElement("div");
                div.innerHTML = "<img src= " + tweet.profile_image_url + "></img> ";
                div.innerHTML += tweet.from_user + " : <b><i>" + tweet.text + "</b></i>";

                // append it to tweet div
                tweetDiv.appendChild(div);
            }
        }
    </script>
</head>
<body>
<div id="tweet">
</div>
<!--Specifying search term and callback function-->
<script src="http://search.twitter.com/search.json?q=Sachin%20Tendulkar&rpp=10&callback=getTweets"></script>
</body>
</html>

Bye


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s