'How to retrieve query parameters from GET request using javascript? [duplicate]
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
});
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
