开发者

PHP + JSON Not Working Correctly

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

<script type="text/javascript">

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

开发者_如何学JAVA// 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜