我目前正在我的网站上建立对多种语言的支持。网站的主要语言是荷兰语,我增加了英语。一切都很好,但我博客上的ajax类别过滤器却不是这样。
荷兰语版本工作正常,英语版本就不行了。
分类过滤器似乎在英文版的博客上生成了正确的url,但它并没有显示正确的帖子:当你点击分类过滤器的英文版上的一个分类时,它会返回每一篇荷兰语的帖子(这是主要语言)。
同样的事情也发生在分页上...
我就是想不出怎么解决这个问题。这是正在使用的JS (底部是分页,顶部是类别过滤器):
$(function() {
// Filter projects and posts
$(document).on("change", ".category-selection-field input[type=checkbox]", function(){
var slugs = $('.category-selection-field input[type=checkbox]:checked')
.map(function(){return $(this).attr("data-slug")})
.get()
.join(",");
var post_type = $(this).attr("data-post-type");
var get_url = "/apis?categories="+slugs+"&post_type="+post_type;
window.history.pushState(null, null, "?categories=" + slugs);
$.ajax({url: get_url , success: function(result){
$("#post-card-container").html(result).hide().fadeIn(500);
}});
});
// Ajaxify the pagination
$(document).on("click", ".paginate-navigation-js a", function(e){
e.preventDefault();
var stored_params = $(this).attr("href").split("?")[1];
if(!stored_params.includes("post_type")){
stored_params += "&post_type=" + $(".category-selection-field input[type=checkbox]").attr("data-post-type");
}
var get_url = "/apis?"+stored_params;
if(get_url != ""){
$.ajax({url: get_url , success: function(result){
$("#post-card-container").html(result).hide().fadeIn(500);
$('html,body').animate({
scrollTop: $("#post-card-container").offset().top
}, 500);
}});
}
})
});有没有办法解决这个问题?我猜想这是一个url的问题,因为/en/添加到网站的英文版本的url?
该网站是用html/liquid建立的。如果您需要更多信息,请让我知道。
The url of the Dutch blog (这是主语言url)
The url of the English blog (这就是问题所在)
我真的希望你们能帮我解决这个问题,因为我迷路了!:)
发布于 2018-12-11 01:00:12
不要紧,我可以通过将HTML标记更改为:
<html lang={{request.language}}>
并将js更改为:
$(function() {
// Filter projects and posts
var lang = $("html").attr("lang");
$(document).on("change", ".category-selection-field input[type=checkbox]", function(){
var slugs = $('.category-selection-field input[type=checkbox]:checked')
.map(function(){return $(this).attr("data-slug")})
.get()
.join(",");
var post_type = $(this).attr("data-post-type");
var get_url = "/"+ lang +"/apis?categories="+slugs+"&post_type="+post_type;
window.history.pushState(null, null, "?categories=" + slugs);
$.ajax({url: get_url , success: function(result){
$("#post-card-container").html(result).hide().fadeIn(500);
}});
});
// Ajaxify the pagination
$(document).on("click", ".paginate-navigation-js a", function(e){
e.preventDefault();
var stored_params = $(this).attr("href").split("?")[1];
if(!stored_params.includes("post_type")){
stored_params += "&post_type=" + $(".category-selection-field input[type=checkbox]").attr("data-post-type");
}
var get_url = "/"+ lang +"/apis?"+stored_params;
if(get_url != ""){
$.ajax({url: get_url , success: function(result){
$("#post-card-container").html(result).hide().fadeIn(500);
$('html,body').animate({
scrollTop: $("#post-card-container").offset().top
}, 500);
}});
}
})
});https://stackoverflow.com/questions/53704745
复制相似问题