Using variable named post in ajax

I want to prefix post_name1 but failed
How should I do
sample: prefix_post_name1, as

function gonder(id, prefix){
	var message = "text";
              type: "POST",
              url: "gonder.php", 
              data: { prefix + "post_name1" : id, "post_name2" : message},
              success: function(data){ 

Thank you

You’re trying to define an object with a variable key.

{ [prefix + "post_name1" ]: id, "post_name2" : message}

Putting square brackets around the expression will work on most browsers.

1 Like

yes, it worked
Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service