如何在单击href时重定向到URL?

时间:2019-04-23 03:04:43

标签: javascript html reactjs fetch href

我的问题开始于尝试在单击href时重定向到URL,我在POST请求中传递带有URL的请求有效负载,包含用户名和密码的请求有效负载,并且基本上试图在链接上进行自动身份验证。请建议这种方法是否正确以及如何实现。谢谢!

我已经尝试使用create Element函数创建href,并在提取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),})
   }

1 个答案:

答案 0 :(得分:0)

您应该改为在不使用此关键字的情况下调用manageMailWeb函数 就像这样manageMailWeb