窗口位置未按预期工作

Window Location Not Working as Expected

本文关键字:工作 位置 窗口      更新时间:2023-09-26

我希望以下JavaScript函数重定向到与我的路由文件匹配的URL。

function getUrl() 
{   
    var hash= $('#hashText').val();
    // When the user has not entered a hash, alert to inform them.
    if (!hash)
    {
        alert("Please enter a hash first.");
    }
    else
    {
        alert("Redirecting to ... http://localhost:8080/tasks/" + hash);
        window.location = "http://localhost:8080/tasks/" + hash;
    }
}

这是我的路由文件中的相应路由条目。

GET     /tasks/:hash                controllers.Application.getTask(hash: Int)

然而,此功能的结果是:

http://localhost:9000/tasks?hash=2014281623

如果您将代码更改为:

var url = 'http://localhost:9000/tasks/';
url += escape(hash);
window.location = url;