首页 > 解决方案 > 如何将变量添加到 URL

问题描述

如何在代码中的 URL 中插入两个变量?我已经在 URL 的末尾插入了变量 filtertype。url 中的单词“slug”应替换为变量 slug。

$('body').on('click','.profile-filter',function(e) {
    e.preventDefault();
    var filtertype = $(this).data("filtertype");
    var slug = $(this).data("slug");

    $.ajax({
        type: 'GET',
        url: '/profile/timeline/post/slug/?' +filtertype,
        success: function (data) {
            $('#profile_content').html(data);
        },
        error: function (xhqr, data) {
            _toastr_new(data, "top-full-width", "error", false, '.toastr-notify', 0);
        }
    });
});

标签: jqueryvariablesadd

解决方案


不确定我是否正确理解了这个问题,但简单的 Javascript 连接不起作用?像这样:

url: '/profile/timeline/post/'+slug+'/?'+filtertype,

推荐阅读