6

I'm facing a problem which should be really simple to solve, but I am lost as of now.

I have a url: http://search.twitter.com/search.json?q=bacon

Using JavaScript (not JQuery or php. Just JavaScript), I want to read this JSON string and parse it. That's it.

Thanks!

1

1 Answer 1

14

You'll be restricted by the SOP (XMLHttpRequests can only be made to URI's on the same domain; JSON can only be retrieved via this method). To bypass this you'll have to use JSONP instead (other explanation*).

It seems the endpoint supports JSONP, so you can do:

function foo(response) { // response is already a JavaScript object } var script = document.createElement("script"); script.src = "http://search.twitter.com/search.json?q=bacon&callback=foo"; document.body.appendChild(script); 

* Disclaimer: Yep, thats my blog

Sign up to request clarification or add additional context in comments.

2 Comments

gave you a +1 and a 5/5 on your blog for fast and precise answer;)
Thanks a lot! Love your blog! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.