我正在尝试从 header 中提取代码,这是对 ajax 查询的响应。当我在 javascript 中使用调试器时,使用 xhr.getAllResponseHeaders 没有输出,我无法在 dom 文档中找到响应。该值不会在 url 本身中返回,只会在查询字符串参数中返回,因此我尝试从那里获取它。这可能吗?
这是我的 Google 检查的图片(我在我想要获取的代码下划线了。)
Google Inspect Header / Query String Parameters
这是我的代码:
$(function() {
$(".btn.getauthzcode").click(function() {
var frapptokenid = readCookie('iPlanetDirectoryPro');
$.ajax({
url: "http://[myurl]:8181/openam/oauth2/authorize?realm=/&client_id=OpenIG&response_type=code&redirect_uri=http://[myurl]:8181/openam&scope=uma_protection&save_consent=0&decision=Allow",
type: "GET",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, GET, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, X-Token, x-token",
headers: {
"accept": "application/json",
"dataType": "jsonp",
"content-type": "application/json;odata=verbose",
"iPlanetDirectoryPro": frapptokenid,
},
success: function(data, status, xhr, url) {
debugger
console.log(url);
console.log(xhr.getAllResponseHeaders());
)},
failure: function(data) {
console.log(data);
}
});
});
});
最佳答案
function wrapper(url) {
$.ajax({
url,
success: function() {
console.log(url);
},
}
}
emmm,如果库没有提供一些变量,我们需要创建一个闭包,将它们保存在变量中
关于javascript - 从 header 获取查询字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46397126/