Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSONPjQuery跨域错误_Javascript_Jquery_Ajax_Json_Jsonp - Fatal编程技术网

Javascript JSONPjQuery跨域错误

Javascript JSONPjQuery跨域错误,javascript,jquery,ajax,json,jsonp,Javascript,Jquery,Ajax,Json,Jsonp,我正在尝试使用jQuery和jsnop检索IMDB页面的源代码,使用以下代码: $(document).ready(function (){ var url = "http://www.imdb.com"; var success = function(data){ // work }; $.ajax({ type: 'GET', url: url,

我正在尝试使用jQuery和jsnop检索IMDB页面的源代码,使用以下代码:

$(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);
          }
        });
});
我遇到以下错误:

object error
parse error

事实上,问题在于格式,因为您的 这将返回基本上是xml格式的html,但您的ajax调用需要JSON格式,请尝试yahoo ypl

//像这样

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);
});

ajax请求是否运行success或error函数?这是因为您根本不了解JSON和JSONP是什么。IMDB的主页返回HTML,而不是JSON,也不是JSONP。你想做的是不可能的。看到了吗