James
James

Reputation: 4354

Accessing data returned by GET request using Javascript

Hi I'm trying to use Javascript to write a chrome application that will show your last number of tweets but I'm having trouble getting the tweets. I'm a newbie to javascript but I have searched quite a bit and can't find an understandable answer to this.

From chrome and twitter I have the following code.

<script type="text/javascript">
var req = new XMLHttpRequest();
req.open(
"GET",
"https://api.twitter.com/1/statuses/user_timeline.json?
include_entities=true&include_rts=true&screen_name=twitterapi&count=3")
</script> 

This GET request works but how do I use the data it returns with javascript?

Upvotes: 0

Views: 213

Answers (2)

ArVan
ArVan

Reputation: 4275

The result is in the req.responseText. You can append it o your document, to see what the response is. It actually depends on what is the response. I mean maybe you need to alert the response, or show it somewhere, or put it in a condition operator and compare with something... Some basoc use:

alert(req.responseText); document.body.innerHTML+=req.responseText;

Upvotes: 1

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143081

It is somewhere in req.responseText. That is, you need to set req.onreadystatechange and once it's ready you'll have it in there.

Upvotes: 0

Related Questions