を使用しているページがありますwikipedia api
。しかし、JSON
クロスドメイン制限には使用できないため、使用しますJSONP
。私のコードは次のようになります
<body>
<script type="text/javascript">
function res(data){
alert(data);
};
</script>
<script type="text/javascript" src="http://en.wikipedia.org/w/api.php?action=opensearch&search=api&callback=res&limit=10&namespace=0&format=jsonfm">
</script>
</body>
res
ここでは、URL で指定されたコールバック関数を提供しています。私がfirebugで見たように、応答は次のようになりました
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MediaWiki API Result</title>
</head>
<body>
<br />
<small>
You are looking at the HTML representation of the JSON format.<br />
HTML is good for debugging, but probably is not suitable for your application.<br />
See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or
<a href='/w/api.php'>API help</a> for more information.
</small>
<pre>
res([
"api",
[
"API",
"Apiales",
"Apiaceae",
"Apia",
"Apicomplexa",
"Apicomplexa lifecycle stages",
"Apidae",
"APIA Leichhardt Tigers",
"Apical membrane",
"Apical consonant"
]
])
</pre>
</body>
</html>
これは、サーバーがコールバック関数に含まれる応答を送信していることを意味しますがres
、この関数はブラウザーによって実行されません (alert
呼び出されていません)。Firefox 5 を使用しています。