Writing different PHP code for different HTML buttons (AJAX)

Viewed 98

I'm trying to write different PHP code for different HTML <button> elements, but apparently it applies to all the buttons on the page. Here's one of my buttons:

<button name="plus" id="plus" type="button" onclick="plus()">+</button> 

Here's the function I tried to make, it applies to all the buttons on the page:

$(document).ready(function() {
    $("button").click(function() {
        $.ajax({
            type: 'POST',
            url: 'plus.php',
            success: function(data) {
                //
            }
        }); 
    }); 
});

The questions:

  1. How do I write functions for specific buttons?

  2. Why do I have to write type="button" for them to work?

  3. Where do I write AJAX functions? In <head></head> or anywhere in the body?

3 Answers
Related