【发布时间】:2013-09-29 14:58:17
【问题描述】:
我无法从下面的代码中通过 jQuery.support.cors = true; 行打印成功。包括 jQuery.support.cors = true; 行会给出警告信息。那么如何在不丢失功能的情况下避免这种情况呢?我的主要目标是调用一个返回 JSON 数据的 REST Web 服务,我必须利用 JSON 数据。请帮助我如何实现这一目标。请提供工作样本
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.getJSON demo</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<script>
jQuery.support.cors = true;
$.ajax ({
url: 'http://json-cricket.appspot.com/score.json',
datatype: "json",
success: function (e) {
// Success callback
alert("sucess");
}})
</script>
</body>
</html>
【问题讨论】:
-
我认为选项是
dataType,而不是全部小写,但不确定有多大的不同,如果 jquery 可以处理它,不记得了。 api.jquery.com/jQuery.ajax -
"会给出警告信息" 哪个信息?跨域问题?
-
我认为这是一个跨域 ajax 请求? stackoverflow.com/questions/11736431/…试试jsonp