gpt4 book ai didi

javascript - 引用错误: window is not defined Javascript

转载 作者:行者123 更新时间:2023-11-28 19:55:43 25 4
gpt4 key购买 nike

app.post("/web/suggest_oncall", function(req, res){
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
console.log(getQueryVariable("list"));
});

我试图从查询中提取“list”的值并将其显示在控制台中。我到底该怎么做才能识别窗口?

最佳答案

说真的,服务器上没有window,但是req.url应该包含当前的URL。

app.post("/web/suggest_oncall", function(req, res){
function getQueryVariable(variable) {
var url = req.url; // gets the URL
var query = url.split('?').pop().substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
console.log(getQueryVariable("list"));
});

关于javascript - 引用错误: window is not defined Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22618372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com