문제

Im trying to use this api that gives me a json. But I can't display any info. I got this code in Jquery:

$(document).ready(function(){
  $("#search").click(function(){
      var title = $("#words").val().replace(/\s/g,"+");
      var url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?q="+title+"&apikey=ng6gbx7vdpwmyfwd7vp5g799" + "?callback=?";

   $.getJSON(url, null, function(data){           
           alert(data.total);

   });
  });
});

Why? I have no idea.

도움이 되었습니까?

해결책

The API only supports JSONp. so you need to do the following

$(document).ready(function(){
    $("#search").click(function(){
        var title = $("#words").val().replace(/\s/g,"+");
        var url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?q="+title+"&apikey=ng6gbx7vdpwmyfwd7vp5g799";

         $.ajax(url, {
             dataType: "jsonp",
             success: function(data){           
                 alert(data.total);
             }  
         });
    });
});

See this fiddle: http://jsfiddle.net/rpTm3/

updated fiddle with alert: http://jsfiddle.net/rpTm3/1/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top