Because this is a cross-domain request you can only do this with a proxy or with JSONP. Fortunately DuckDuckGo supports JSONP, so you just need to ensure that you add a callback parameter to the URL request like:https://api.duckduckgo.com/?q=JavaScript&format=json&pretty=1&callback=jsonp ...或在jQuery的ajax方法中使用适当的jsonp参数,例如:... or use the appropriate jsonp parameter with jQuery's ajax method, something like:$('#ddgAPI').on('keyup', function(e) { if (e.which === '13') { $.ajax({ type: 'GET', url: 'https://api.duckduckgo.com/', data: { q: $(this).val(), format: 'json', pretty: 1 }, jsonpCallback: 'jsonp', dataType: 'jsonp' }).then(function (data) { console.log(data); }); }}); 这篇关于从Web API提取和读取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 20:53