使用self.location.href重定向不起作用

时间:2016-04-13 08:15:13

标签: javascript jquery

我的应用程序上有一个按钮,当用户点击它时,我希望重新加载页面。这是我的按钮:

<button type="button" class="btn btn-success-outline add_sol">Ajouter</button>

它调用了一个javascript函数:

 $(function() {

    $(".add_sol").click(function(){

        var e = document.getElementById("select_sols");
        var sol = e.options[e.selectedIndex].value;

        var string = window.location.pathname+"_ajouter_sol"+window.location.search+"&id_sol="+sol;
        alert(string); //The alert displays the right adress

        self.location.href(string);

    });
});

我使用string变量发出警报,它会显示我想要的内容。但我不知道为什么self.location.href不起作用。

2 个答案:

答案 0 :(得分:1)

尝试window.location.href - 应该完美运作

答案 1 :(得分:0)

使用location.reload();可以刷新页面

window.location = string;进行重定向