How can I send an Ajax Request on button click from a form with 2 buttons?
<p>I want to send a request from one page to another from a form which has 2 buttons:</p>

<pre class="lang-html prettyprint-override"><code>&lt;form method="post"&gt;
    &lt;button id="button_1" value="val_1" name="but1"&gt;button 1&lt;/button&gt;
    &lt;button id="button_2" value="val_2" name="but2"&gt;button 2&lt;/button&gt;
    &lt;input id="access_token" type="hidden" name="access_token" value="&lt;?php echo $_SESSION['access_token']; ?&gt;" /&gt;
&lt;/form&gt;
</code></pre>

<pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
  $("#button_1").click(function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: "/pages/test/",
      data: {
        id: $("#button_1").val(),
        access_token: $("#access_token").val()
      },
      success: function(result) {
        alert('ok');
      },
      error: function(result) {
        alert('error');
      }
    });
  });

  $("#button_2").click(function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: "/pages/test/",
      data: {
        id: $("#button_2").val(),
        access_token: $("#access_token").val()
      },
      success: function(result) {
        alert('ok');
      },
      error: function(result) {
        alert('error');
      }
    });
  });
});
</code></pre>

<p>How can I improve this code and maybe merge it into one function?</p>