Call the Watercress API, error
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.
Just started to learn PHP, the thigh to help solve
Page
搜索
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("
"); }); }, }); } });
Reply content:
Call the Watercress API, error
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.
Just started to learn PHP, the thigh to help solve
Page
搜索
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("
"); }); }, }); } });
I just did a little search. Ajax cross-domain issues, and now I'm thinking of using the JSONP format, and then adding the server side
Header ("Access-control-allow-origin: *"); # Cross-domain processing