代码示例:(标识:jquery_ajax_load_err)
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").load("wrongname.xml",function(response,status,xhr){
if (status=="success")
{
$("div").html("<ol></ol>");
$(response).find("artist").each(function(){
var item_text = $(this).text();
$('<li></li>').html(item_text).appendTo('ol');
});
}
else
{
$("div").html("An error occured: <br/>" + xhr.status + " " + xhr.statusText)
}
});
});
});
</script>
</head>
<body>
<p>Artists</p>
<div></div>
<button>获得 CD 信息</button>
<p>本例中使用的 XML 文件是一个不存在的文件wrongname.xml</p>
</body>
</html>