2

I am trying to retrieve the source code of an IMDB page using jQuery and jsnop, using the following code:

$(document).ready(function (){

        var url = "http://www.imdb.com";

        var success = function(data){
            // work
        };

        $.ajax({
          type: 'GET',   
          url: url,
          data:{todo:"jsonp"},
          dataType: "jsonp",
          crossDomain: true,         
          cache:false,
          success: success,
          error:function(jqXHR, textStatus, errorThrown){
            console.log(errorThrown);
            console.log(textStatus);
          }
        });
});

I am getting following errors:

object error
parse error
Veger
  • 37,240
  • 11
  • 105
  • 116
Sahidul Islam
  • 489
  • 5
  • 18
  • Does the ajax request run the success or error function? – Jonathon Blok Dec 17 '14 at 12:39
  • 2
    That is because you haven't *at all* understood what JSON and JSONP is. The homepage of IMDB returns HTML, not JSON, not JSONP. What you're trying to do simply isn't possible. See http://en.wikipedia.org/wiki/JSON, http://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it, http://stackoverflow.com/questions/2887209/what-are-the-differences-between-json-and-jsonp and http://www.mattlunn.me.uk/blog/2011/10/json-vs-jsonp/ – Matt Dec 17 '14 at 12:49

1 Answers1

2

Actually the problem is the format, as your are hitting http://www.imdb.com which will return html which is basically a xml format, but your ajax call expecting a JSON format, try yahoo ypl

//like this

var site = 'http://www.imdb.com';
var encoderUrl = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + site + '"') + '&format=xml&callback=?';
$.getJSON(encoderUrl, function(data){
    console.log(data);
});
rohit verma
  • 101
  • 1
  • 7