# Using variable named post in ajax

**URL:** <https://www.phphelp.com/t/using-variable-named-post-in-ajax/34208>\
**Category:** Javascript & Ajax\
**Created:** [November 3, 2021, 8:45am UTC](https://www.phphelp.com/t/using-variable-named-post-in-ajax/34208 "2021-11-03T08:45:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adem](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@Adem](https://www.phphelp.com/u/Adem)\
**Post date:** [November 3, 2021, 8:45am UTC](https://www.phphelp.com/t/using-variable-named-post-in-ajax/34208/1 "2021-11-03T08:45:57Z")

</div>

Hello,  
I want to prefix post\_name1 but failed  
How should I do  
sample: **prefix\_post\_name1** , as

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

```

Thank you

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [November 3, 2021, 7:36pm UTC](https://www.phphelp.com/t/using-variable-named-post-in-ajax/34208/2 "2021-11-03T19:36:15Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![Adem](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@Adem](https://www.phphelp.com/u/Adem)\
**Post date:** [November 4, 2021, 7:42am UTC](https://www.phphelp.com/t/using-variable-named-post-in-ajax/34208/3 "2021-11-04T07:42:36Z")

</div>

yes, it worked  
Thank you
