如何将变量添加到 URL
How can i add variable to 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,
嗯我猜你想连接字符串,你可以像这样使用纯 js
'/profile/timeline/post/'+ slug +'/?' + filtertype
或者使用 ES6 模板字面量特性
`/profile/timeline/post/${slug}/?${filterType}`
如何向代码中的 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,
嗯我猜你想连接字符串,你可以像这样使用纯 js
'/profile/timeline/post/'+ slug +'/?' + filtertype
或者使用 ES6 模板字面量特性
`/profile/timeline/post/${slug}/?${filterType}`