I have a locale
variable that can hold values such as en
, fr
, or es
. The goal is to include this locale key in an AJAX request as part of the data
parameter.
let locale = "en";
let name = "example";
$.ajax({
url: "/path",
method: "PUT",
data: {characteristic: {`${locale}`: name}},
success: function(){},
error: function(){}
})
I attempted to use ES6's string interpolation for this purpose, but it resulted in a syntax error. How can I achieve this functionality?
The desired outcome, based on the locale, should be:
{en: "example"}
{fr: "example"}
{es: "example"}