新手求助web api跨域问题

powerqiang821 2016-04-02 12:49:18
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>搜索</title>
<meta charset="utf-8" />
</head>
<body>
<script src='jquery-1.12.2.js'></script>
<script>
$(document).ready(function () {
$("#Button1").click(function () {
//$.get('http://res.chinacloudsites.cn/list', function (data) {
// alert('1');
// //console.log(data);
// //$('#TextArea1').html(data);
//});
//$.get('http://res.chinacloudsites.cn/list',{keyword:"轻音"},'JSONP')
// .success(function () { alert("success") })
// .error(function () { alert("error") })
// .complete(function () { alert("error") });
$.ajax({
url: "http://res.chinacloudsites.cn/list?keyword='轻音'",
type: 'GET',
Datatype: 'JSONP',
//success: function (data) { alert("success") }
}).success(function () { alert("success"); }).done(function () { alert("success"); }).error(function (XMLHttpRequest, textStatus, errorThrown) { alert("error"); })
});
});
</script>
<input id="Text1" type="text" /><input id="Button1" type="button" value="查询" /><input id="Button2" type="button" value="重置" />
<textarea id="TextArea1" rows="2" cols="20"></textarea>
</body>
</html>


这个执行后总是调用error的操作,求帮忙看下,返回的是200,但是还是提示跨域
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
powerqiang821 2016-04-03
  • 打赏
  • 举报
回复
最后还是在服务端添加Access-Control-Allow-Origin:*即可
slwsss 2016-04-02
  • 打赏
  • 举报
回复
dataType: 'jsonp',
powerqiang821 2016-04-02
  • 打赏
  • 举报
回复
引用 2 楼 powerqiang821 的回复:
[quote=引用 1 楼 slwsss 的回复:] dataType: 'jsonp',
改了以后有回应了,可是还是进到错误处理 提示好像是SyntaxError: missing ; before statement[/quote] 这个是在火狐浏览器中出现的,是不是需要添加什么??
powerqiang821 2016-04-02
  • 打赏
  • 举报
回复
引用 1 楼 slwsss 的回复:
dataType: 'jsonp',
改了以后有回应了,可是还是进到错误处理 提示好像是SyntaxError: missing ; before statement

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧