我得到了简单的ajax调用我无法理解为什么它没有运行成功方法,尽管chrome开发人员工具显示它正在获取请求的响应。
$( document ).ready(function() {
var url_API="http://moviesapi.herokuapp.com/cinemas/find/"+"PL15RH";
$.ajax({
type: 'GET',
url: url_API,
dataType: "jsonp",
crossDomain:true,
success: function (response) {
alert(1);
}
});
});
答案 0 :(得分:1)
API不支持jsonp。你得到500 (Internal Server Error)
。
它确实支持JSON,但是你得到了经典的No 'Access-Control-Allow-Origin' header is present on the requested resource
CORS错误。您需要在heroku API上显式发送Access-Control-Allow-Origin
标头:
标题属性:
Access-Control-Allow-Origin: *
更详细的解决方案:"No 'Access-Control-Allow-Origin' header is present on the requested resource"
答案 1 :(得分:0)
试试这个:
jQuery(document).ready(function($) {
var url_API="http://moviesapi.herokuapp.com/cinemas/find/"+"PL15RH";
$.ajax({
type: 'GET',
url: url_API,
dataType: "json",
crossDomain:true,
success: function (response) {
alert(response);
}
});
});