javascript - 如何在单击 href 时重定向到 URL?
问题描述
我的问题首先是尝试在单击 href 时重定向到 URL,并且我正在通过 POST 请求中的 URL 传递请求有效负载,请求有效负载包含用户名和密码,并且基本上尝试在链接上进行自动身份验证。请就这种方法是否正确以及如何实现这一点提出建议。谢谢!
我已经尝试使用 create Element 函数创建一个 href 并在 fetch api 中传递带有有效负载的 URL。
export default class PortComponent extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{headerName: "Details", field: "details", autoHeight: true,
cellRenderer: (params) => {
var link;
link = document.createElement('a');
link.href = "#";
link.onclick=this.manageMailWeb();
link.innerText = "Manage Mail + Web";
link.target="_blank";
div.appendChild(link);
}
return div;
};
}
async manageMailWeb(){
let name,pass, url = "https://example.net/OS4/index.php";
this.state.items.map(e => {
name=e.serviceDetails.domainName;
pass=e.serviceDetails.domainPassword;
});
await redirectService(name,pass,url);
}
static async redirectService(name,pass,url,serviceId){
const user=name,
url = "",
appoverride = "Login",
CustomLogin = "http://example.net/login/close.html",
CustomError = "http://example.net/login/close.html",
CustomShell = "http://example.net/login/close.html",
CustomLanguage = 'en',
login_x = "1",
login_y="1";
return await fetch(url, {
mode: "no-cors",
method: "POST" ,
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
},
body: JSON.stringify(user,pass,appoverride,
CustomLogin,CustomError,CustomShell,CustomLanguage,login_x,login_y),})
}
解决方案
您应该像这样调用没有 this 关键字的 manageMailWeb 函数manageMailWeb
推荐阅读
- emacs - 如何在表达式寄存器中粘贴寄存器
- java - “字段列表”中的未知列“factura0_.id_coche”
- html - 我正在尝试使用模型表单小部件更新模型。除了 forms.DateField 之外的所有字段都可以在 HTML 表单中进行编辑
- r - 使用 dplyr 子集嵌套数据框
- unity3d - 我从游戏中删除了 Unity 广告服务,但 google play 仍然说我的应用包含广告
- css - 在缩略图上附加播放按钮
- python-3.x - Pyspark 数据框 OrderBy 列列表
- python - 如何在 Python 中解析 JSON 并将 2 个字段放入字典中?
- python - 如何在python中循环列表?
- javascript - 将 Next.js 升级到 v6.0.3 后 Storybook 无法编译