我在尝试从我的 Restful Web 服务接收字符串时遇到问题。我的 ajax 代码看起来像这样
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function showName(str)
{
if (str=="")
{
document.getElementById("playerInfo").innerHTML="Player information will be listed here.";
return;
}
var n = "path/to/jboss"+str;
document.getElementById("testURL").innerHTML=n;
$.ajax({
type: "GET",
url: n,
dataType: "html",
success:function(resp){
document.getElementById("playerInfo").innerHTML=resp;
},
error:function(e){
document.getElementById("playerInfo").innerHTML="Error: " + e;
}
});
}
</script>
</head>
<body>
<form action="">
<select name="id" onchange="showName(this.value)">
<option value="">Select an id number:</option>
<option value="51902">51902</option>
<option value="51907">51907</option>
<option value="51916">51916</option>
</select>
</form>
<div id="testURL"></div>
<div id="playerInfo">Player information will be listed here.</div>
</body>
</html>
正在传递的 str 是该页面上我的应用程序的参数。假设返回一个 HTML 字符串,但它总是出错并且永远不会成功。谁能帮我诊断这个问题?