How to post response to another URL after close iframe in php

Good day, i am trying to find solutions to post/reroute a response receive from a URL1 (ccRtnResponse1) to URL2 (ccTxnResponse2) after closing iframe in function URL1

<script>

    document.getElementById('mpiReqForm').submit();

    // Get iframe and loading circle elements
    const iframe = document.getElementById('transactionIframe');
    const loadingCircle = document.getElementById('loading-circle');

    // Hide loading circle and show iframe when the iframe has finished loading
    iframe.onload = function() {
        loadingCircle.style.display = 'none';
    };

    // Function to remove the iframe
    function removeIframe() {
        if (iframe) {
            iframe.remove(); // Remove the iframe element from the DOM
        }
    }

    // Listen for messages from the iframe
    window.addEventListener("message", function(event) {
        console.log('Message received:', event.data);
        // Check if the message is to close the iframe
        if (event.data === "closeIframe") {
            removeIframe(); // Call the function to remove the iframe
            // response receive from function ccRtnResponse1 will be pass to function ccTxnResponse2
        }
    });
</script>

so after receive the response

  public function ccRtnResponse1(Request $request)
{
  // This is in the iframe response, after processing
  echo '<script>window.parent.postMessage("closeIframe", "*");</script>';

  $data=$request->all;
  // repost the response $data to function ccTxnResponse2 after 'close iframe"

}

i would like to pass the $data to URL2(ccTxnResponse2)

  public function ccTxnResponse2(Request $request)
{
  dd($request->all());
}

i have tried to use appendChild but it seems not working. I hope to get some suggestion here. thank you