简体   繁体   English

如何在ReactJS中使用POST数据重定向用户?

[英]How to redirect user with POST data in ReactJS?

I need to redirect user to external url with POST data. 我需要使用POST数据将用户重定向到外部网址。 How could I achieve this in ReactJS? 我如何在ReactJS中实现呢?

I need to redirect the user to external bank deposit link. 我需要将用户重定向到外部银行存款链接。 I thought bank link will respond whit redirect url but it doesn't. 我以为银行链接会响应丝毫重定向网址,但事实并非如此。 My thinking is that I need to make a POST request to that bank link and redirect user to that page. 我的想法是,我需要向该银行链接发出POST请求,并将用户重定向到该页面。 Tell me if I'm wrong. 告诉我我是否错。 Here is what I've tried so far. 到目前为止,这是我尝试过的。

This redirect happens in dispatch so rendering a form is not an option 此重定向发生在分派中,因此无法呈现表单

fetch(body.success.message.redirect_url, {
  method: "POST",
  body: JSON.stringify(body.success.message.request_data)
})
.then(response => {
  console.log(response);
})
.catch(error => {
  throw error;
});

Create a form element and submit it. 创建一个表单元素并提交。 This is how jquery-ujs does it. 这就是jquery-ujs的工作方式。 Obviously you need to rewrite this basic code to react, but you get the idea. 显然,您需要重写此基本代码以作出反应,但是您明白了。

  var href = body.success.message.redirect_url,
    form = $('<form method="post" action="' + href + '"></form>'),

  form.hide().appendTo('body');
  form.submit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM