在 ajax post 请求中设置 href 值

Set href value in ajax post request

我有 java servlet 应用程序 jquery,在我的应用程序中我有数据 table 和电影,

var ProjectionManager = {
getAll : function(){
            $.get('ProjectionsServlet', function(data){
                $('#projectionsTable1').DataTable ({
                    data: data.projections,
                    paging: false,
                    info: false,
                    searching: false,
                    autoWidth: true,
                    columns: [
                            {
                            "data": 'movie',
                            render:function(data, type, row){
                                return '<a id="movieRedirectFromProjection" data-name="' + data + '" href="#">' + data + '</a>';
                                }
                            },
                            {data : 'dateOutput'}
                        ]
                })
            })
        }
}

当我点击电影栏时,我想用该电影的 ID 更新浏览器中的 href 值。 我在这个 table 中没有电影 ID 值,所以我查询了数据库 returns 整部电影 object 按标题。

var MoviesManager = {
getMovieByTitle: function(title) {
            params = {
                'action': 'getMovieByTitle',
                'title': title
            };
            $.post('MoviesServlet', params, function(data){
                //I want to set href value here with data.movie.id that comes from servlet
                //I think it's something like this         e.target.href = "#";
                //                                         e.target.href += '?id=' + data.movie.id;
                //but I can't use event here, can I?
            })
        }
}

这就是我处理数据中电影列点击的方式table

$('body').on('click', '#movieRedirectFromProjection', function(e){
        var name= $(this).attr("data-name");
        MoviesManager.getMovieByTitle(name);

    });

使用window.location.href获取浏览器的url,附加id后赋值给浏览器