ExpressJs" window.location.href"没有重新加载页面

时间:2015-10-19 10:24:39

标签: jquery node.js express ejs

我在nodejs项目中使用ExpressJs,其中视图文件的扩展名为.ejs。

因为我已经编写了Js代码 - 选择框选项更改在哪里我正在重新加载页面。

对于重新加载页面,我写了下面的代码

window.location.href = window.location.host.replace( /[\?#].*|$/, "/equipment/"+$('#rigSelect').val());

但它没有重新加载页面而是调用canceled状态的ajax操作

它无法在expressjs中工作 - window.location.href应重新加载页面,但调用ajax操作。

让我知道我应该如何重新加载页面?

编辑

Html /脚本代码

<%- include header.ejs %>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script type="text/javascript">
            $(function () {
                var rigRecords = [ rigRecords ]
                var rigRows = <%- JSON.stringify(rigRecords) %>

                var rigId = [ rigId ]
                var rigId = <%- JSON.stringify(rigId) %>

                    function populate(selector) {
                        $.each(rigRows, function (index, val) {
                            if(rigId == val.id){
                                $(selector).append('<option value="'+val.id+'" selected>'+val.name+'</option>');
                            }else{
                                $(selector).append('<option value="'+val.id+'">'+val.name+'</option>');
                            }
                        })
                    }

                    populate('#rigSelect');

                    var records = [ records ]
                    var rows = <%- JSON.stringify(records) %>

                    $.each(rows[0], function (index, val) {
                    //$.each(val, function (index1, val1) {
                            var newTr = '<tr><td>'+val.name+' (VP Id:'+val.viewpoint_id+')</td></tr>';
                            $('#tbl_equipment').find('.tblBody').append(newTr);
                    //})
                    });
            });
            function reloadPage(){
                //req.redirect('http://google.com');
                //window.location.reload();
                window.location.href = window.location.host.replace( /[\?#].*|$/, "/equipment/"+$('#rigSelect').val());

            }
</script>

1 个答案:

答案 0 :(得分:1)

我已经改变了

window.location.href = window.location.host.replace( /[\?#].*|$/, "/equipment/"+$('#rigSelect').val());

window.location.href = '/equipment/'+$('#rigSelect').val();

它正常工作:)

相关问题