【问题标题】:Set href value in ajax post request在ajax post请求中设置href值
【发布时间】:2020-05-09 21:23:00
【问题描述】:

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

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 值。 我在这个表中没有电影 id 值,所以我查询了数据库,它按标题返回整个电影对象。

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?
            })
        }
}

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

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

    });

【问题讨论】:

  • this 回答你的问题了吗?
  • 使用window.location.href获取浏览器的url,添加id后赋值给相同
  • @CNKR window.location.href 正是我想要的,谢谢。

标签: jquery ajax href


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-04-24
    • 2013-07-06
    • 1970-01-01
    • 2016-05-20
    • 2017-03-10
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多