You don’t need .each, because $(".button").on("click") already add handlers to all .button. In your case, it loops every .button and every time it will add handlers, to them all, on each turn.
According to jQuery docs, the .post() expect object or string as the second argument:
This is my jquery code that takes the data attribute of a specific button having the class name “.button”. I’m trying to post this data attribute to a PHP file having the name “to.php”. I’ve also tried this with $.ajax method but in PHP it says the term is undefined when I echo $_POST[‘term’]. Can someone help me in posting data attributes to a PHP file?