我有一个页面,我正在使用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 中命名的回调函数。正如我在萤火虫中看到的那样,响应来了
<!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。这有什么问题?