0

I just started using JSON and found this example from http://imdbapi.com/:

<script type="text/javascript">

// IMDb ID to Search
var imdbLink = "tt1285016";

// Send Request
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET", "http://www.imdbapi.com/?i=" + imdbLink, false);
http.send(null);

// Response to JSON
var imdbData = http.responseText;
var imdbJSON = eval("(" + imdbData + ")");

// Returns Movie Title
alert(imdbJSON.Title);

</script>

But it just returns a blank page. What is wrong?

3
  • 1
    What browser are you using? the ActiveXObject is (more than likely) IE only. Commented Aug 3, 2011 at 19:54
  • i am using internet explorer. Commented Aug 3, 2011 at 19:56
  • It works for me on IE9, but it does throw a security error, so your security level might not allow you to run ActiveX. Joey's next answer, about how to use jQuery is the more modern way to go. Commented Aug 3, 2011 at 19:59

1 Answer 1

2

I'm sorry not to directly answer your question, but here is a jQuery version:

var imdbLink = "tt1285016";

// Send Request
$.getJSON("http://www.imdbapi.com/?i=" + imdbLink + "&callback=?", function(data) {
    alert(JSON.stringify(data));
});

There are a couple possible issues with your code.

1.) ActiveX is IE only, not firefox, chrome, safari, etc.

2.) You have a cross-domain issue.

Example Fiddle

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

Comments

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.