显示的是Null,我后端的servlet写的是将转置后的矩阵输出,在前端console.log打印控制台也没有结果
<!DOCTYPE html>
<html>
<head>
<title>Matrix Calculation</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<meta charset="UTF-8">
<title>Jquery引入</title>
<!-- <script src="js/jquery-3.3.1.min.js" type="text/javascript" ></script>-->
<script type="text/javascript">
<!-- Jquery引入的测试 -->
$(function(){
alert("执行Jquery的语法成功");
})
</script>
<script>
$(document).ready(function() {
$('#matrix-form').on('submit', function(e) {
e.preventDefault(); // 阻止表单默认提交行为
// 获取用户输入的行数和列数
var rowCount = parseInt($('#row-count').val());
var colCount = parseInt($('#col-count').val());
console.log(rowCount)
// 构建动态表格
var tableHtml = `<table>`;
for (var i = 0; i < rowCount; i++) {
tableHtml += '<tr>';
for (var j = 0; j < colCount; j++) {
$('#col-count')
tableHtml += `<td><input type="text" name="matrix[${i}][${j}]}"></td>`;
// tableHtml += '<td><input type="text" name="matrix['+i+']['+j+']"></td>';
console.log("hala")
console.log(document.getElementsByName(`matrix[${i}][${j}]`));
console.log($('input[name="matrix[' + i + '][' + j + ']"]').val());
}
tableHtml += '</tr>';
}
tableHtml += '</table>';
// 替换表格内容
$('#matrix-table').html(tableHtml);
});
$('#calculate-btn').on('click', function() {
// 发送矩阵数据到后端进行计算
var formData = $('#matrix-form').serialize();
$.ajax({
url: 'matrixServlet',
type: 'POST',
data: formData,
success: function(response) {
// 在前端展示计算结果
$('#result').html(response);
},
error: function(xhr, status, error) {
console.log('Error:', error);
}
});
});
});
</script>
</head>
<body>
<h2>Matrix Calculation</h2>
<form id="matrix-form">
<label for="row-count">行数:</label>
<input type="number" id="row-count" name="rowCount" min="1" required>
<br>
<label for="col-count">列数:</label>
<input type="number" id="col-count" name="colCount" min="1" required>
<br>
<input type="submit" value="创建表格">
</form>
<br>
<div id="matrix-table"></div>
<br>
<button id="calculate-btn">计算</button>
<br>
<div id="result"></div>
</body>
</html>
发送ajax请求到servlet按理说应该抛出空指针或者parseint异常,但是idea的控制台也没报错