您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

本地调用豆瓣API

2025/7/17 18:34:33发布20次查看
调用豆瓣的api,报错
xmlhttprequest cannot load https://api.douban.com/v2/book/search?q=%e7%94%b5%e6%9c%ba%e5%ad%a6&count=10. no 'access-control-allow-origin' header is present on the requested resource. origin 'http://mytest' is therefore not allowed access.
刚开始学php,求大腿帮忙解决
页面
搜索


js
$('#go').click(function(){ if($('input').val()==''){ alert(请输入关键词); }else{ var sq=$('input').val(); $.ajax({ type:get, url:https://api.douban.com/v2/book/search, datatype:json, data:{ q:sq, count:10 }, success:function(data){ $.each(data.books, function(i,book) { $(#showbook).append(
); }); }, }); } });

回复内容: 调用豆瓣的api,报错
xmlhttprequest cannot load https://api.douban.com/v2/book/search?q=%e7%94%b5%e6%9c%ba%e5%ad%a6&count=10. no 'access-control-allow-origin' header is present on the requested resource. origin 'http://mytest' is therefore not allowed access.
刚开始学php,求大腿帮忙解决
页面
搜索


js
$('#go').click(function(){ if($('input').val()==''){ alert(请输入关键词); }else{ var sq=$('input').val(); $.ajax({ type:get, url:https://api.douban.com/v2/book/search, datatype:json, data:{ q:sq, count:10 }, success:function(data){ $.each(data.books, function(i,book) { $(#showbook).append(
); }); }, }); } });

刚才我搜了一下没事ajax跨域问题,具体现在我想到的就是用jsonp格式,然后在server端加上
header(access-control-allow-origin: *); # 跨域处理
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product