ReferenceError:窗口未定义Javascript

时间:2022-11-06 14:30:55
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"));
});

I am trying to pull the value of "list" from the query and display it in the console. What exactly can I do for window to be recognized?

我试图从查询中提取“列表”的值,并将其显示在控制台中。我能做些什么才能让窗户得到认可?

1 个解决方案

#1


3  

Seriously, there is no window on a server, but req.url should contain the current URL.

说真的,服务器上没有窗口,但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"));
});

#1


3  

Seriously, there is no window on a server, but req.url should contain the current URL.

说真的,服务器上没有窗口,但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"));
});