0

I have the following code:

var twitterUrl = escape("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + username);
$.ajax({
    type: "GET",
    url: "twitter.js?url=" + twitterUrl,
    dataType: "json",
    success: function(d, status, req) {
        var tweets = eval('(' + d + ')');
        showTweets(tweets);
    }
});

I want the twitter.js file to get the twitterUrl variable and process it to obtain the json file generatd by the twitter API. The questions are:

  1. How can I read and parse the twitterUrl in the twitter.js file?
  2. How can I simulate a stream_get_contents PHP function in JavaScript to parse and process the twitter link and pass the result back to the original page?

1 Answer 1

0

1.

var twitterUrl = location.search.match(/[?&]url=(.*?)(&|$)/i);
twitterUrl = twitterUrl && twitterUrl[1];

2. Where myMethod is the function you want to send the data to:

var script = document.createElement('script');
script.src = twitterUrl + '&callback=myMethod';
var head = document.getElementsByTagName('head')[0];
head.insertBefore(script, head.firstChild);

So for example myMethod:

var myMethod = function(data) {
  alert('Your name is ' + data.user.name);
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.