2015-02-09 52 views
0

这里是我的Ajax调用:Ajax正在返回数据,但我看不到它?

jQuery.ajax({ 
    type: 'GET', 
    datatype: 'application/json', 
    url: URL, 
    dataType: 'jsonp', 
    success: function(data) { 
     console.log(data); 
    }, 
    error: function(data) { 
     console.log(data); 
     } 
}); 

当我点击Chrome开发工具的网络,我看到一个状态200,响应数据都在那里,但它并没有控制台登录出来反正,我尝试。 相反,这里是我得到:

Refused to execute script from 'http://localhost:3000/api/bikes?apiKey=*****&callback=jQuery17204357656354550272_1423492504648&_=1423492968710' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled. 
VM1680:11 Object {readyState: 4, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…} 

任何解释?

+0

你为什么试图指定2个数据类型? jsonp应该是为跨域请求指定的数据类型 - 我认为你应该在你的情况下删除dataType:'jsonp'。 – 2015-02-09 14:59:50

+0

这是一个跨域请求 – TheJKFever 2015-02-10 00:32:15

+0

看看这里:http://stackoverflow.com/questions/24528211/refused-to-execute-script-from-because-its-mime-type-application-json-is - 似乎像一个非常类似的问题,你的。 – 2015-02-10 11:07:29

回答

0

请尝试使用,而不是“JSONP”

“JSON”如果“URL”不返回一个回调函数如预期的“JSONP”,你需要使用“JSON”而不是“JSONP”

jQuery.ajax({ 
    type: 'GET', 
    datatype: 'application/json', 
    url: URL, 
    dataType: 'json', 
    success: function(data) { 
     console.log(data); 
    }, 
    error: function(data) { 
     console.log(data); 
    } 
}); 
+0

使用json的问题是,然后我得到一个CORS错误。 – TheJKFever 2015-02-10 00:31:45

+0

如果你的要求是要克服XMLHttpRequest相同的域策略,我建议你看看_here_ http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp – 2015-02-10 02:37:35

相关问题