Javascript Can';t使用html表单元素从JSON获取信息,使用wikimedia获取JSON方法

Javascript Can';t使用html表单元素从JSON获取信息,使用wikimedia获取JSON方法,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试提交一些东西来搜索表单,并从j-son那里获取信息 $(“#target1”)。提交(功能(e){ e、 预防默认值(); var x=document.getElementById(“输入”).value; 变量url=”https://en.wikipedia.org/w/api.phpaction=query&format=json&prop=revisions&list=search&titles=&rvprop=content&srsearch=“+x; var=函数(te

我正在尝试提交一些东西来搜索表单,并从j-son那里获取信息

$(“#target1”)。提交(功能(e){
e、 预防默认值();
var x=document.getElementById(“输入”).value;
变量url=”https://en.wikipedia.org/w/api.phpaction=query&format=json&prop=revisions&list=search&titles=&rvprop=content&srsearch=“+x;
var=函数(teh){
$(“#target2”).text(继续。继续);
}
$.getJSON(url,地址);
});


看起来是CORS问题。请参阅此处了解解决方案

将origin=*添加到URL查询参数

$("#target1").submit(function(e) {
  e.preventDefault();
  var x = document.getElementById("input").value;
  var url = "https://en.wikipedia.org/w/api.php?origin=*&action=query&format=json&prop=revisions&list=search&titles=&rvprop=content&srsearch=" + x;
  var the = function(teh) {
    $("#target2").text(teh.continue.continue);
  }
  $.getJSON(url, the);
});

请说明您面临的问题。getJSON方法没有调用我要求的信息。您遇到了一个跨源访问错误
XMLHttpRequest无法加载https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&list=search&titles=&rvprop=content&srsearch=hello%20world. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://s.codepen.io因此不允许访问。
使用ajax调用,类型为
JSONP
<代码>$.ajax({url:url,数据类型:'jsonp',//注意!jsonp看起来像是它的CORS问题。请参阅此处了解解决方案