我正在写一个简单的网站,作为输入一个成语,并从牛津字典中返回其含义和示例.这是我的想法:
我发送请求到以下URL:
http://www.oxfordlearnersdictionaries.com/search/english/direct/?q=[idiom]
例如,如果成语“不走远”,我会发送一个请求到:
http://www.oxfordlearnersdictionaries.com/search/english/direct/?q=not+go+far
http://www.oxfordlearnersdictionaries.com/definition/english/far_1#far_1__192
在这个页面上,我可以提取成语的含义和例子.
这是我的测试代码.它将提醒响应网址:
<input id="idiom" type="text" name="" value="" placeholder="Enter your idiom here"> <br> <button id="submit" type="">Submit</button> <script type="text/javascript"> $(document).ready(function(){ $("#submit").bind('click',function(){ var idiom=$("#idiom").val(); $.ajax({ type: "GET",url: 'http://www.oxfordlearnersdictionaries.com/search/english/direct/',data:{q:idiom},async:true,crossDomain:true,success: function(data,status,xhr) { alert(xhr.getResponseHeader('Location')); } }); }); }); </script>
问题是我有一个错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.oxfordlearnersdictionaries.com/search/english/direct/?q=by+far. This can be fixed by moving the resource to the same domain or enabling CORS.