Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用windows.locaton.href或windows.locaton.replace的Javascript重定向不起作用。错误:未定义窗口_Javascript_C#_Razor - Fatal编程技术网

使用windows.locaton.href或windows.locaton.replace的Javascript重定向不起作用。错误:未定义窗口

使用windows.locaton.href或windows.locaton.replace的Javascript重定向不起作用。错误:未定义窗口,javascript,c#,razor,Javascript,C#,Razor,我已经查看了有关windows.locaton.href和windows.locaton.replace不工作的所有问题,但仍然无法找出此重定向在JavaScript中不工作的原因。当使用submit单击按钮时,我将调用两个JS函数 <input type="submit" 这两个函数在Javascript中定义为: <script> function NotifyUserOfNewBudgets(val) { alert("New Budget will b

我已经查看了有关windows.locaton.href和windows.locaton.replace不工作的所有问题,但仍然无法找出此重定向在JavaScript中不工作的原因。当使用submit单击按钮时,我将调用两个JS函数

 <input type="submit" 

这两个函数在Javascript中定义为:

<script>

function NotifyUserOfNewBudgets(val) {
    alert("New Budget will be saved. NewVal=" + val);
    var ireturn;

    document.getElementById("NewBudgetID").value = val;
    document.getElementById("formMode").value = "Update";
}

function redirect2MainLookup(primaryFilename) {
    var loc = window.location.pathname;
    var host = document.location.host;
    var dir = loc.substring(0, loc.lastIndexOf('/'));

    //Replace the word Edit with blank so this redirects correctly
    var newdir = dir.replace("NewBudget", "");

    var newpath = host + newdir + primaryFilename;
    alert('newpath location = http://' + newpath);
    try {
        windows.locaton.href = "http://" + newpath;
         //window.location.replace('http://' + newpath);
    } catch (err) { alert("Error: " + err);}

}
</script>

函数NotifyUserOfNewBudgets(val){
警报(“将保存新预算。NewVal=“+val”);
var-ireturn;
document.getElementById(“NewBudgetID”).value=val;
document.getElementById(“formMode”).value=“更新”;
}
函数redirect2MainLookup(primaryFilename){
var loc=window.location.pathname;
var host=document.location.host;
var dir=loc.substring(0,loc.lastIndexOf('/');
//将“编辑”一词替换为空白,以便正确重定向
var newdir=dir.replace(“NewBudget”,“NewBudget”);
var newpath=host+newdir+primaryFilename;
警报('newpath location=http://'+newpath);
试一试{
windows.locaton.href=“http://”+newpath;
//window.location.replace('http://'+newpath);
}catch(err){alert(“Error:+err);}
}

我在try()catch()中得到的错误是未定义windows,然后它将保持在同一页上。使用windows.locaton.replace()也会出现同样的错误。我有很多网页做重定向,不明白为什么这一个失败

您有许多拼写错误<代码>窗口
是您要查看的对象<代码>位置是您希望访问的属性。现在,您正在使用
windows.locaton
windows
不是一件事,
locaton
也不是。注意
未定义的
错误,它们可以告诉您许多有关代码状态的信息。

您是否尝试过使用windows.location而不是windows.location?特别是在Daxton,我纠正了这些,我不知道我没有看到这些。我已使用window.location.href=“http://”+newpath再次尝试了此操作;和window.location.replace(“http://”+newpath);而重定向仍然没有发生。问题:在将值保存到带有submit的表单后是否可以重定向?我不认为我可以提交值并根据我看到的其他帖子返回表单,但我希望我能得到关于这一点的明确答案。因此,走另一条路,我在C代码中添加了以下内容:Response.Redirect(“~/Budget/listbughtsbyfiscalyear”);这会在我运行代码以在post发生后使用新值更新数据库后重定向到新页面。啊,我明白了。是的,如果您使用的是MVC,则在
表单
提交后需要在
控制器
级别进行重定向,因为
表单
提交会刷新页面。如果希望在发布后重定向,则需要使用类似jQuery的AJAX的方法发布表单数据,然后在成功响应后重定向。