Commit dd97b4e5 authored by Zhu yizheng's avatar Zhu yizheng
Browse files

适配后端

parent 943bca90
......@@ -23,7 +23,7 @@ submitButton.on('click', function () {
}
$.ajax({
url: '/comment/add',
url: 'http://localhost:8080/comment/add',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ name, content }),
......@@ -45,7 +45,7 @@ submitButton.on('click', function () {
// 加载评论
function loadComments(page) {
$.get('/comment/get', { page, size: commentsPerPage }, function (res) {
$.get('http://localhost:8080/comment/get', { page, size: commentsPerPage }, function (res) {
if (res.code === 0) {
totalComments = res.data.total;
displayComments(res.data.comments);
......@@ -70,7 +70,8 @@ function displayComments(comments) {
deleteButton.on('click', function () {
if (!confirm('确定删除这条评论吗?')) return;
$.post('/comment/delete', { id: comment.id }, function (res) {
// 修正:将id放在URL的query参数中
$.post('http://localhost:8080/comment/delete?id=' + comment.id, function (res) {
if (res.code === 0) {
alert('删除成功');
loadComments(currentPage);
......
......@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<script src="comment.js" defer></script>
<title>评论区</title>
......@@ -14,7 +15,7 @@
<h3 class="formTitle2">comment content</h3>
<input type="text" id="comment" placeholder="请输入评论内容">
<br>
<button id="submit" class="commomButton">提交</button>
<button id="submit" class="commonButton">提交</button>
</div>
<div class="commentsArea">
<ul id="commentsList"></ul>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment