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都不工作,我認爲它附加數據但立即消失,你能想到爲什麼發生這種情況 –