我试图简单地打印从Servlet响应中获得的值。
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$('#Identify').click(function() {
var numberList = document.getElementById("inputString");
var kth = document.getElementById("nthHighest");
dataString = "inputString=" + numberList.value + "&nthHighest="+kth.value;
$.ajax({
url : "/HelloHalozen/HighestNumber",
data : dataString,
type : "POST",
dataType : "text",
success : function( responseText ) {
//$('#result').text(responseText);
$("#result").append(responseText);
},
error : function( xhr, status ) {
alert("Sorry, there was a problem!");
},
complete : function( xhr, status ) {
alert("The request is complete!");
}
});
});
});
</script>`
<button id="Identify">Identify</button>
<div id="result"></div>
`
从我的servlet我做了以下事情:
response.getWriter().write("You have successfully made Ajax Call..." );
$("#result").append(responseText);
。
你能帮我吗?我是Ajax和jQuery的新手。
提前谢谢。
答案 0 :(得分:0)
尝试在服务器上关闭PrintWriter。也许这可以提供帮助。
下面的代码可能会产生一些亮点
String answer = "You have successfully made Ajax Call...";
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.print(answer);
out.close();
也许来自服务器端和客户端的完整源代码可能有助于理解您的问题。