js/ajax提交请求成功后跳转到另一个页面

实际场景:在弹窗中输入数据提交后,需要跳转到另一个页面展示(不是父页面)

parent.location.href = 'url';
Dialog.closeSelf();
js/ajax提交成功后采用以下方式跳转:
1、本页面跳转:"window.location.href"、"location.href" 
2、上一层页面跳转:"parent.location.href"
3、最外层的页面跳转:"top.location.href"
举例说明:
如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写
"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转
如果D页面中有form的话,
<form>: form提交后D页面跳转
<form target="_blank">: form提交后弹出新页面
<form target="_parent">: form提交后C页面跳转
<form target="_top"> : form提交后A页面跳转
  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是一个简单的登录界面的 HTML 代码,包含用户名、密码和登录按钮,并且在登录成功跳转到其他页面: ```html <!DOCTYPE html> <html> <head> <title>登录</title> <meta charset="utf-8"> <style> body { background-color: #f5f5f5; font-family: Arial, sans-serif; } h1 { text-align: center; margin-top: 50px; } form { width: 300px; margin: 0 auto; background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 5px; } label { display: block; margin-bottom: 10px; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 3px; font-size: 16px; margin-bottom: 20px; box-sizing: border-box; } input[type="submit"] { background-color: #4CAF50; color: #fff; border: none; padding: 10px 20px; font-size: 16px; border-radius: 3px; cursor: pointer; transition: background-color 0.3s ease; } input[type="submit"]:hover { background-color: #3e8e41; } </style> </head> <body> <h1>登录</h1> <form id="login-form" action="http://example.com/login" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <input type="submit" value="登录"> </form> <script> // 获取表单元素和提交地址 const form = document.getElementById('login-form'); const action = form.action; // 监听表单提交事件 form.addEventListener('submit', function(event) { event.preventDefault(); // 阻止表单默认提交行为 // 发送 AJAX 请求 const xhr = new XMLHttpRequest(); xhr.open('POST', action); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { alert('登录成功!'); window.location.href = 'http://example.com/other-page'; // 跳转到其他页面 } else { alert('登录失败!'); } }; xhr.send(new FormData(form)); }); </script> </body> </html> ``` 这个登录界面使用了 HTML、CSS 和 JavaScript,采用了简洁的扁平化设计风格,使用了表单元素来实现输入框和登录按钮,同时添加了一些简单的样式来美化界面。在表单提交时,通过 AJAX 发送请求到远程服务器,如果服务器返回状态码为 200,则表示登录成功,此时通过 `window.location.href` 跳转到其他页面。你可以根据需要进行修改和完善。注意,这里的 `action` 属性需要设置为远程服务器的登录接口地址。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoneWalker、

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值