部分 index.html
文件:
<button id="getAllGroups" type="button" class="btn btn-primary">Groups</button>
然后我的 js
文件:
GET: $(document).ready(
function () {
// GET REQUEST
$("#getAllGroups").click(function (event) {
event.preventDefault();
ajaxGet();
});
// DO GET
function ajaxGet() {
$.ajax({
type: "GET",
url: "checkGroups",
success: function (result) {
if (result.status == "success") {
var custList = "";
$.each(result.data,
function (i, group) {
var Html = "<tr>" +
"<td>" + group.groupId + "</td>" +
"<td>" + group.groupName + "</td>" +
"</tr>";
console.log("Group checking: ", group);
$('#tbody').append(Html);
});
console.log("Success: ", result);
window.location.href = "groupsPagik"
} else {
console.log("Fail: ", result);
}
},
});
}
})
我的控制器:
@RestController
public class GroupController {
@Autowired
GroupService groupService;
@GetMapping("/checkGroups")
public ResponseEntity<Object> getAllGroups() {
ServiceResponse<List<Group>> response = new ServiceResponse<>("success", groupService.getAll());
return new ResponseEntity<Object>(response, HttpStatus.OK);
}
}
一切都很好,如果我把获得的数据打印到同一页上- index.html
:
<div class="row">
<div class="col-md-8">
<table border="2">
<thead>
<th>Group Id</th>
<th>Group name</th>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
但是我想把这些数据(组)打印到新的html页面上。因此,我的问题是如何做到这一点:打印获得的数据不是同一页,而是另一页。
暂无答案!
目前还没有任何答案,快来回答吧!