How do I pass the language through ajax request I have an ajax function in the javascript file that calls for the data in a custom module. But the problem is it always get the data for the default language. In my case it is 'en'. How do I get the data for another language. 

$language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId(); 


This method always returns the default language for ajax requests. How do I get the data for the language that is mentioned in the url.

ajax:

$.ajax({
    url: "/gallery/view", 
    method :'POST',
    data: {
        category : category,
        propertyId : propertyId,
        isCorporate : isCorporate,
        brandId : brandId,
    },
    success: function(result){}
});


routing :

eme_gallery.view:
  path: '/gallery/view'
  defaults:
      _controller: 'Drupal\eme_gallery\Controller\ViewGalleryImage::view'
      _title: 'Image Gallery'
  requirements:
      _permission: 'access content'
You will need to change the URL of your AJAX call to include the language prefix. So this:

url: "/gallery/view", 


Will be this:

url: "/ja/gallery/view",