【发布时间】:2015-11-24 07:11:04
【问题描述】:
您好,我正在尝试使用来自网站的 json 数据,但我无法使用 jsonp 执行此操作,不确定是我编码错误还是服务问题。
<script>
$(function () {
$("#frmInstrumento").submit(function(event) {
alert("hello");
$.ajax({
url: "https://www.camaradenegocios.com/api/get/",
// The name of the callback parameter, as specified by the YQL service
jsonp: "promotions",
// Tell jQuery we're expecting JSONP
dataType: "jsonp",
// Work with the response
success: function( response ) {
alert(response);
console.log( response ); // server response
}
});
});
});
</script>
要使用的 url 是 https://www.camaradenegocios.com/api/get/promotions 如果我浏览,我可以看到数据,但不能使用 Jquery 使用它。
【问题讨论】:
-
请将error属性放在success属性之后,并给它一个console.log()或者alert()来显示错误,然后报告。
-
跨源请求被阻止:同源策略不允许读取位于camaradenegocios.com/api/get 的远程资源。 (原因:CORS 请求失败)。