jquery - 如何将变量添加到 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);
}
});
});
解决方案
不确定我是否正确理解了这个问题,但简单的 Javascript 连接不起作用?像这样:
url: '/profile/timeline/post/'+slug+'/?'+filtertype,
推荐阅读
- pytorch - torch.matmul 给出 RuntimeError
- python - Python中for循环中每个子图的单独标题
- r - 使用 ggplot,如何根据日期组合线和多边形?
- sql - 如何从sql中的列中减去数据
- java - 如何在 Eclipse 中找到类的用法?
- ruby-on-rails - Rails前端尝试将自动生成的数据保存到没有表单的数据库中
- react-native - 使用 useState 钩子,但是 setter 函数在运行时未定义
- java - 通过代理调用方法,该代理使用内部带有 Transactional 注释的另一个方法,是否会为后一种方法创建事务?
- php - PHP - 多个(很多)if(isset)检查 - 有没有捷径
- javascript - js 我可以用 FileReader 读取文件的一部分吗?