سؤال

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