【发布时间】:2011-02-11 05:27:54
【问题描述】:
我是 Ajax 和 jQuery 方面的新手,需要一些帮助...
以下 url 生成一个我想在我的页面上使用的 xml 文件: http://ws.spotify.com/search/1/track?q=foo
当我使用 firebug 时,似乎什么都没有回来。我做错了什么?
这是我的代码的样子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: 'http://ws.spotify.com/search/1/track?q=foo',
type: 'GET',
contentType: "application/xml; charset=utf-8",
error: function(){
alert('Error loading XML document');
},
success: function(xml){
alert("success");
$(xml).appendTo("#result");
}
});
});
</script>
</head>
<body>
<div id="result">
</div>
</body>
</html>
【问题讨论】:
-
该 xml 文件是否与您调用它的脚本位于同一域中?
-
当您说 什么都没有返回时,我假设您的意思是您的
success回调正在被调用,但没有数据。对吗? -
纯 XML 回复不会显示在浏览器中。