【发布时间】:2011-10-14 07:59:46
【问题描述】:
我有一个使用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>
这里我在 url 中提供名为 res 的回调函数。正如我在萤火虫中看到的那样,响应来了
<!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。这有什么问题?
【问题讨论】:
标签: callback jsonp wikipedia-api