You can use JavaScript to achieve this functionality. The specific steps are as follows:
- Add a submit button to the form and add an event listener to it.
- Use the XMLHttpRequest object in the event listener to submit form data to the server.
- Check the status code returned by the server in the onreadystatechange event handler of the XMLHttpRequest object. If it is 200, the submission is successful, and a prompt box will pop up.
- Add a "Confirm" button in the prompt box. When the user clicks the Confirm button, use the window.location.href property to jump to a new page.
Here is sample code:
<form id="myForm">
<!-- 在表单中添加需要提交的表单元素 -->
<input type="text" name="name">
<input type="email" name="email">
<button type="submit" id="submitBtn">提交</button>
</form>
<script>
const form = document.getElementById('myForm');
const submitBtn = document.getElementById('submitBtn');
submitBtn.addEventListener('click', function(event) {
event.preventDefault(); // 防止表单自动提交
const xhr = new XMLHttpRequest();
xhr.open('POST', '/submit');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
alert('提交成功!');
window.location.href = '/newpage'; // 跳转到新页面
}
};
xhr.send(new FormData(form));
});
</script>Please note that the above sample code is only used to demonstrate how to implement the described functions, and you need to adjust it according to the actual situation.