0
我试图从JSP页面进行AJAX调用,但是我无法将返回的响应呈现给textarea。 Ajax调用给予正确的回应,我能够登录控制台,但无法追加到textarea的Ajax从JSP页面调用servlet页面
下面是代码:
的index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<style type="text/css">
body {
background-image:
url('https://cdn.crunchify.com/wp-content/uploads/2013/03/Crunchify.bg_.300.png');
}
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Initialization</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"
type="text/javascript"></script>
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<form>
<textarea rows="6" cols="25" id="request"></textarea>
<button id="Submit">Submit</button>
<textarea rows="6" cols="25" id="response"></textarea>
</form>
</body>
</html>
的script.js
$(document).ready(function() {
$('#Submit').click(function() {
$.ajax({
type : 'POST',
data : {
request : $('#request').val()
},
url : 'Initialization',
success : function(result) {
console.log(result);
$('#response').text(result);
}
});
});
});
尝试使用$('#response')。val(result); –
尝试'.html(结果)' –
我试过val @GurkanYesilyurt和html都不工作,我认为它附加数据但立即消失,你能想到为什么发生这种情况 –