怎么从前端请求 获得后端的请求页面 API client

后端用express 写的 调用Mollie API client请求支付页面 后端是localhost:8000
输入URLlocalhost:8000/api?issuer=ideal_ABNANL2A 会直接跳到支付页面使用已选择的银行。

前端是localhost:3000 package.json已有proxy
用axios get请求后端 /api 没有任何反应 为什么直接用后端输入URL可以?
后端代码如下

  app.get('/api', (req, res) => {

  console.log(req.query.issuer)
   let selectedIssuer =req.query.issuer;

   if (!selectedIssuer) {
   console.log('No selected bank Issuer')
   return
     }



 const orderId = new Date().getTime();

  // After which you can create an iDEAL payment with the selected issuer.
  mollieClient.payments
    .create({
  amount: { value: '10.00', currency: 'EUR' },
  description: 'Test payment',
  redirectUrl: `https://example.org/redirect?orderId=${orderId}`,
  webhookUrl: `http://example.org/webhook?orderId=${orderId}`,
  metadata: { orderId },
  method: 'ideal',
  issuer: selectedIssuer,
})
.then(payment => {
  // Redirect the consumer to complete the payment using `payment.getPaymentUrl()`.
  res.redirect(payment.getPaymentUrl());
   

})
.catch(error => {
  // Do some proper error handling.
  res.send(error);
});
});

前端代码如下

        class App extends Component {
          
        
          handleSend=()=>{
            const obj=document.getElementById('issuer');
            const index=obj.selectedIndex; //序号,取当前选中选项的序号
            const val = obj.options[index].text;
        
            axios.get('/api',{
              params:{
                issuer:val }
            }
             
            )
            
          
        }
          render() {
            
          
            return (
              <div>
               Hallo world
               <form >
                <select 
                  id= 'issuer'
                  name = 'issuer'>
                <option value='ideal_ABNANL2A'>ABN AMRO</option>
                <option value='ideal_ASNBNL21'>ASN Bank</option>
                <option value='ideal_BUNQNL2A'>bunq</option>
                <option value='ideal_INGBNL2A'>ING</option>
                <option value='ideal_KNABNL2H'>Knab</option>
                <option value='ideal_MOYONL21'>Moneyou</option>
                <option value='ideal_RABONL2U'>Rabobank</option>
                <option value='ideal_RBRBNL21'>RegioBank</option>
                
                </select>
                <button onClick={this.handleSend}>Select issuer</button>
                </form> 
                  
              </div>
              
            );
          }
        }
    浏览器 和终端都没有任何报错 但是也没有反应
阅读 2.6k
1 个回答

楼主,看下浏览器的控制台,报什么异常,有红色的提示没有

两个思路,排查下
1,proxy 代理写法有问题
2,有跨域

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题