PHP和Javascript事件处理

I know that php is a server-side language. However I am confused on how to hook up a html button event to a page that uses php. I understand this will probably involve Javascript, some css and html and maybe Ajax. I've been looking at some examples but they don't explain the important pieces I am looking for. In summary I want to see the code for the click event and how php gets notified there was a click.

I apologize if this is a strange question. I'm used to old application programming and I'm trying to understand some of these newer practices.

The actual click event will never be sent to PHP. The outcome of the click is what the server (PHP) will see.

For example, if your button redirects the user to a different page, your PHP will be "notified" as soon as the GET request reaches your sever.

For a form element, the submit button will issue a POST request to a certain URL, that request is what you can "interpret" as the click event. The same goes for an AJAX request.

This is a button in your form

<form id="form1">
    <div class="col-md-8">
                          <button type="submit" class="submitbtn" id="submitbtn">Save</button>
                        </div>
</form>

This is your java-script, usually jquery or even angularjs is awesome to do this trick

$("#form1").submit(function () { 


$.ajax({
                type: "POST",
                cache: false,
                data:  $("#form1").serializeArray(),
                success: function (data) {
                    if (data.ok) {
                       alert('Awesomeness');
                    }
                    else {
                        alert('Crapness');
                    }

                },
                error: function () {
                    console.log("html error");
                     alert('Crapness');
                }
            });

})

Then back in your php you just recieve the data like old school programming, with a post variable

$something = $_POST['Forminput'];
if(!empty($something)){

   //do something and return result
   echo "{\"ok\":\"true\", \"data\":\"some data for u\"}";
}