javascript - 为什么ajax不将我重定向到另一个html页面?

标签 javascript jquery html ajax

我想在成功的ajax请求后将用户重定向到另一个html页面,但没有任何反应。我不得不提的是,html 页面需要身份验证,但此时用户发出请求时他已经登录了。

这是js:

$("form").submit(function (env) {
    env.preventDefault();
    $("#submitbtn").prop('disabled', true);
    $("#form_result").text("");
    var request = JSON.stringify($("#newRequest-form").serializeObject());
    console.log(request);
    $.ajax({
        method: "POST",
        url: "/api/holidays",
        data: request,
        contentType: "application/json",
        dataType: "html",
        success: function () {
            window.location.href("summary.html");
            /*$("#form_result").text("Submitted succesfully");
            $("form").addClass('hidden');*/
        },
        error: function (error) {
            $("#form_result").text("Error: creating the request. Status: " + error.status + " - " + error.statusText);
            $("#submitbtn").prop('disabled', false);
        }
    });
});

最佳答案

window.location.href("summary.html");

不是一个函数,而是一个属性。试试这个:

window.location.href = "summary.html";

关于javascript - 为什么ajax不将我重定向到另一个html页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38869272/

相关文章:

html - 如何设置选择元素的箭头样式

javascript - 如何制作 svg 元素(例如矩形)scrollIntoView?

javascript - 我如何保证我的枚举定义在 JavaScript 中不会改变?

javascript - 将新行字符替换为\r

javascript - 在 jquery 中切换 css 属性?

javascript - 如何清除不透明的附加div高度?

javascript - 连续文本框验证

javascript - document.activeElement.href 在 chrome 中不起作用

html - 如何在react js中获取HTML5数据属性的值

html - CSS 中其他元素宽度的相关宽度