如何以回调的形式返回发送给我的数据?

问题描述 投票:0回答:1

我并不完全熟悉网络开发,所以这可能看起来是一个愚蠢的问题,但请允许我描述一下。

用户选择要购买的商品后,将进行 API 调用,生成 trans_id 并重定向到处理付款的银行页面。无论响应是肯定还是否定,我们都会在付款后被重定向到回调 URL。在我们的例子中,这是/transaction/callback。

我们想要获取在网络 -> 回调 -> 负载中看到的 trans_id

enter image description here enter image description here

这是我的代码,我们必须在其中获取 trans_id

Next Js 应用程序路由器 14.0.4

  "use client"
  import React from 'react';

  export default function Page() {
    return (
      <div className='flex items-center justify-center w-full min-h-[100vh]'>
        <div className="flex flex-col items-center justify-center">
            <h2 className="text-center text-white text-[35px] font-medium font-['Manrope'] uppercase">The order has been taken</h2>
            <p className="text-center mt-4 text-white text-lg font-light font-['Manrope']">All information regarding your order has been sent to the indicated email.</p>
        </div>
      </div>
    );
  }

收到这个trans_id后,我们将向另一个API发出请求以检查状态。问题是我不太明白如何提取它。

任何建议或提示将不胜感激。

javascript web next.js frontend backend
1个回答
1
投票

基本上当你进行API调用时,就会有响应。从网络选项卡中,您可以看到正在发送回给您的响应。

最终在react或基本上的javascript中你应该使用像a这样的东西

const response = await fetch('https://cricova.lol/transaction/callback)
const data = await response.json()
console.log(data)

在该数据变量中,您应该能够访问该数据对象以获得您想要的 trans_id。

© www.soinside.com 2019 - 2024. All rights reserved.