Hi.
I’m making a simple AJAX request to fetch some text content which is then placed on a page. It works perfectly fine, but when I switch to the German version of the site, the AJAX request still fetches the English text. How do I specify that the request should get the translated version of the content?
My AJAX request looks like this (simplified):
$(document).ready(function() {
var teamMemberButton = $(".slider--cell.portrait");
var container_teamMemberText = $("#teamMemberText");
var url = "team" + ".json";
//
teamMemberButton.click(function() {
var teamMember_clicked = $(this).data("member");
//
console.log("Team member clicked: " + teamMember_clicked);
//
$.ajax({
type: "POST",
url: url,
data: { teamMemberURL: teamMember_clicked },
success: function(data) {
container_teamMemberText.text(data.text);
}
});
});
});
It simply checks the »Team Member« that was clicked and gets the related text. The corresponding JSON template looks like this:
// Target Member
$target = $_POST['teamMemberURL'];
$teamMember_text = '';
// Access CMS
$page = page('team');
$teamMember = $page->children()->find($target);
// Get text of team member
$teamMember_text .= $teamMember->item1();
$data['text'] = $teamMember_text;
echo json_encode($data);
I suspect that somewhere I have to specify which translation of the text I want fetched, but I don’t know where or how. Thanks to anyone who can help me out