Steps for redirecting to an external URL with response data following an HTTP POST request:

this.http.post<any>('https://api.mysite.com/sources', [..body], [...header])
  .subscribe(async res => {
    const someData = res.data;
    const url =  res.url;

    window.location.href = url  
})

After redirecting to the specified URL, how can I pass along the someData information?

Answer №1

One way to transfer data is by utilizing query parameters

   this.http.post<any>('https://api.mysite.com/sources', [..body], [...header])
      .subscribe(async res => {
         const someData = res.data;
         const url =  res.url;

         window.location.href = url + `?data1=${yourData1}&data2=${yourData2}`
    })

Upon the arrival of the data in the other application, you can retrieve it as follows:

    private readRedirectionData() {
       const url = window.location.toString();
       const data1 = this.getUrlParameter(url, 'data1');
       const data2 = this.getUrlParameter(url, 'data2');
    }

    private getUrlParameter(url, name) {
       if (!url) {
          return '';
       }
       if (!name) {
          return '';
       }
       name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
       const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
       const results = regex.exec(url);
       return results === null ? '' : decodeURIComponent(results[1]);
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Cy.visit() function in Cypress times out and bypasses tests specifically when navigating to a VueJS web application

Having trouble with the Cypress cy.visit() function timing out and aborting tests on a VueJS Web Application? It seems to work fine when opening other non-VueJS sites. Below is my basic configuration setup: [package.json] "dependencies": { "cypres ...

What is the best way to display my to-do list items within a React component

I'm working on a straightforward todo application using fastapi and react. How can I display my todos? I attempted to use {todo.data}, but it's not functioning as expected. Here is my Todos.js component: import React, { useEffect, useState } fro ...

Navigating through tabs in a Meteor application: How to maintain the active tab when using the back button

I am working on a multi-page meteor application where each page includes a navigation template. To switch between pages, I am using iron-router. The user's current page is indicated by setting the appropriate navigation link's class to 'ac ...

Extract images from dynamically loaded JavaScript website

I'm attempting to extract images from a webpage that is rendered using JS, but the picture links in the source code are incomplete. Here is where the images are located: <script language="javascript" type="text/javascript"> </script> < ...

Is there a way to host an AngularJS 2 application without needing to serve all the files in the `node_modules` directory as well?

Struggling to get the Angular 2 seed application up and running. Upon using npm install, a plethora of files are placed into node_modules that seem excessive for what is necessary to serve alongside the seed application code. Is there a way to only serve ...

The React implementation of an OpenLayers map is not responsive on mobile devices

I recently set up an OpenLayers map in a React project and it's working smoothly on desktop browsers. The map is interactive, allowing users to drag, zoom in/out, and display markers as expected. However, I'm facing an issue with touch events on ...

HTML - implementing a login system without the use of PHP

While I am aware that the answer may lean towards being negative, I am currently in the process of developing a series of web pages for an IST assignment in Year 9. Unfortunately, the web page cannot be hosted and our assessor lacks the expertise to utiliz ...

Ensuring Valid Submission: Utilizing Jquery for a Straightforward Form Submission with 'Alajax'

After searching for a straightforward JQuery plugin to streamline the process of submitting forms via Ajax, I stumbled upon Alajax. I found it quite useful as it seamlessly integrates into standard HTML forms and handles all the necessary tasks. However, I ...

"Acquiring the version number in Angular 5: A step-by-step

How can I retrieve the version from my package.json file in Angular 5 project? I am using Angular-Cli: 1.6.7 and npm 5.6.0 Here is a snippet from my enviroment.ts file: export const enviroment = { VERSION: require('../package.json').versio ...

Incorporate a Three.js viewer within a WPF application

I am currently exploring the use of Three.js to develop a versatile 3D renderer that can run seamlessly on various platforms through integration with a "WebView" or "WebBrowser" component within native applications. I have successfully implemented this sol ...

What is the best way to utilize the GET Method with a hashtag incorporated into the URL?

For instance: www.sample.com#?id=10 Currently, I am not able to retrieve any value from $_GET['id']. Despite my attempt to eliminate the hashtag from the URL using JavaScript, no change occurs: $(document).ready(function(){ $(window.location ...

Tips for ensuring a watcher only runs once in each digest cycle, regardless of how many times the property is modified

I am facing an issue with my function $scope.render() that relies on the value of $scope.myProperty to render a chart. Whenever myProperty changes during a digest cycle, I need to ensure that $scope.render() is called only once at the end of the digest cyc ...

Combining and linking 3 RxJS Observables in TypeScript and Angular 4 without nesting to achieve dependencies in the result

I have 3 observables that need to be chained together, with the result from the first one used in the other 2. They must run sequentially and each one should wait for the previous one to complete before starting. Is there a way to chain them without nestin ...

ngTransclude not encompassing any content whatsoever

I am facing an issue with a custom Angular directive that is used in several of my AngularJS views. The directive is set to transclude, but the wrapped content is not appearing. app.directive('card', [function() { return { restrict: "E", ...

Is there a way to add an entire array of child nodes to a parent node in a single operation using JavaScript?

Is there a quick way in JavaScript to attach an array of child nodes to a parent node all at once? I'm looking for a method that will avoid triggering unnecessary repaints. So far, I attempted using parent.appendChild(arrayOfNodes), but it resulted ...

What causes the error "Angular 2 checkbox params.setValue is not functioning properly"?

import { Component } from '@angular/core'; import { GridOptions, RowNode } from 'ag-grid/main'; import { ICellRendererAngularComp } from 'ag-grid-angular'; @Component({ selector: 'qrp-drop-down-selector', ...

Filter out the truthy values in an array with JavaScript

I am currently working with a javascript array called 'foo' which looks like this: var foo = [false,false,true,false,true]; My goal is to eliminate all the 'true' values and only keep the 'false' ones, resulting in this arra ...

What is the proper way to import and define typings for node libraries in TypeScript?

I am currently developing a node package in TypeScript that utilizes standard node libraries such as fs, path, stream, and http. Whenever I attempt to import these libraries in a .ts file, VS Code flags the line with an error message: [ts] Cannot find m ...

Testing an angular function that requires multiple arguments in its constructor

My goal is to conduct unit tests on functions within a component. The constructor for this component requires four arguments. Initially, I attempted to simply set the arguments as (new AClass, new BClass, new CClass, new DClass); however, some of these cla ...

Tips for integrating yarn add/npm install with monorepositories

I am attempting to retrieve a node package from a private monorepo on GitHub, structured similarly to this: monorepoProject --- subProjectA --- subProjectB Both subProjectA and subProjectB are TypeScript projects, following the layout depicted below: ...