這個問題在這里已經有了答案: 如何在 JavaScript 中獲取查詢字串值? (73 個回??答) 2天前關閉。
以下是我的 GET 請求。我正在嘗試檢索 client_id 和 redirect_uri 引數。
https://sdkapp.example.com:8443/central-login/index.html?client_id=dtvClient&redirect_uri=https://www.example3.com:443/callback
然后在同一個 html 頁面內的嵌入式 js 腳本中利用這些值。
Config.set({
clientId: //fetched query parameter for client_id
redirectUri: // fetched query parameter for redirect_uri
});
uj5u.com熱心網友回復:
如果這是在客戶端上,您可以使用URL和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)
如果在服務器上:例如節點也有URL
這是 php 的答案:獲取 URL 查詢字串引數
uj5u.com熱心網友回復:
您可以使用此代碼段:
// Here I've putted direct link for this example but you have to use `window.location.href` if you want to get the dynamic link
const url_string = "https://sdkapp.example.com:8443/central-login/index.html?client_id=dtvClient&redirect_uri=https://www.example3.com:443/callback"; // use window.location.href instead
const url = new URL(url_string);
let clientID = url.searchParams.get("client_id");
let redirectUri = url.searchParams.get("redirect_uri");
console.log(clientID);
console.log(redirectUri);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/441761.html
標籤:javascript jQuery 形式 得到
下一篇:動態表單,包括補丁
