web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Making cross domain call us...

Making cross domain call using JSONP (JSON with padding)

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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


Filed under: HTML 5, JavaScript Tagged: HTML 5, JavaScript

This was originally posted here.

Comments

*This post is locked for comments