Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to retrieve query parameters from GET request using javascript?

Below is my GET request. I am trying to retrieve the client_id and redirect_uri parameters.

https://sdkapp.example.com:8443/central-login/index.html?client_id=dtvClient&redirect_uri=https://www.example3.com:443/callback

And then utilize those values, in a embedded js script within the same html page.

Config.set({
  clientId: //fetched query parameter for client_id
  redirectUri: // fetched query parameter for redirect_uri
  });

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If this is on the client you can use URL and searchParams

// const url = new URL(location.href); // uncomment and delete next line
const url = new URL("https://sdkapp.example.com:8443/central-login/index.html?client_id=dtvClient&redirect_uri=https://www.example3.com:443/callback"); // for example

const obj = {
  "clientId": url.searchParams.get("client_id"),
  "redirectUri": url.searchParams.get("redirect_uri")
};
console.log(obj)

// Config.set(obj)

If on the server: for example node also has URL

And here is an answer for php: Get URL query string parameters

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading