cuốn sách gpt4 ai đã làm

javascript - jQuery 提取 token 并将其传递给 php 位置 header

In lại Tác giả: Walker 123 更新时间:2023-11-28 03:15:19 hai mươi bốn 4
mua khóa gpt4 Nike

我想使用 jQuery 从 API 中提取 token ,然后将其传递给 URL 中的 php 位置 header 参数。

Ví dụ:


$.getJSON('https://example.com/APIENDPOINT', function(data) {
alert(data.access_token)
});


header('Location: https://example.com/auth/?access_token=${data.access_token}');
?>

我不确定我做错了什么,如果有人能给我任何提示,我会很高兴。

câu trả lời hay nhất

也许是这样的:

$.getJSON('https://example.com/APIENDPOINT', function(data) {
window.location.href = 'https://example.com/auth/?access_token=' + data.access_token;
});

如果需要 301 重定向,则仅在服务器端运行(php)

  $json = file_get_contents('https://example.com/APIENDPOINT');
$obj = json_decode($json);
$token = $obj->access_token;
$url = 'https://example.com/auth/?access_token=' . $token ;
header("Location: ".$url, true, 301);
ra();
?>

关于javascript - jQuery 提取 token 并将其传递给 php 位置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59695834/

hai mươi bốn 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress