php-ajax: how to use two submit button on form every one work for different purpose
<p>Before posting to this question i checked below links.
<a href="https://stackoverflow.com/questions/11929471/how-do-i-use-two-submit-buttons-and-differentiate-between-which-one-was-used-to">How do I use two submit buttons, and differentiate between which one was used to submit the form?</a></p>

<p><a href="https://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form">Two submit buttons in one form</a></p>

<p>but i am still facing issue. 
Below are the codes.
<strong>html code</strong></p>

<pre><code>&lt;form name="posting" id="posting" method="post" action="posting_bk.php" role="form"&gt;
    &lt;input class="btn btn-home" type="submit" name="publish" id="publish" alt="Publish" value="Preview and Post" /&gt;
    &lt;input class="btn btn-home" type="submit" name="save" id="save" onclick="return confirm('Are you sure you want to Submit.')" alt="Save" value="Save as Draft" /&gt;&lt;/center&gt;
&lt;/form&gt;
</code></pre>

<p>Here is the php code on <strong>posting_bk.php</strong></p>

<pre><code>    if (isset($_POST['publish'])) {
        # Publish-button was clicked
array_push($res['errors'], 'Publish button');
    echo json_encode($res);
    }
    elseif (isset($_POST['save'])) {
      # Save-button was clicked
array_push($res['errors'], 'Save button.');
    echo json_encode($res);
    }
</code></pre>

<p>Issue is i am not getting any output. i was suppose to get <strong>test publish</strong> or <strong>test save</strong>.</p>

<p>i am planning to use ajax and below is the code i have written for ajax.</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $('document').ready(function() {
        $("#posting").on("submit", function(e) {
            e.preventDefault;
            var btn = $('#publish');

            $.ajax({
                type: 'post',
                url: $('form#posting').attr('action'),
                cache: false,
                dataType: 'json',
                data: $('form#posting').serialize(),
                beforeSend: function() {
                    $("#validation-errors").hide().empty();
                },
                success: function(data) {
                    if (data.success == false) {
                        var arr = data.errors;
                        $.each(arr, function(index, value) {
                            if (value.length != 0) {
                                $("#validation-errors").append('&lt;div class="alert alert-danger"&gt;&lt;strong&gt;' + value + '&lt;/strong&gt;&lt;div&gt;');


                            }
                        });
                        $("#validation-errors").show();
                        btn.button('reset');
                    } else {
                        $("#success").html('&lt;div class="alert alert-success"&gt;Basic details saved successfully. &lt;br&gt; If you want to edit then please goto &lt;a href="edit.php"&gt;Edit&lt;/a&gt;. &lt;div&gt;');
                        $('#title').val('');

                    }
                },
                error: function(xhr, textStatus, thrownError) {
                    alert('Something went to wrong.Please Try again later...');

                    btn.button('reset');
                }
            });
            return false;
        });
    });
&lt;/script&gt;
</code></pre>

<p>If i didn't use ajax then it is working fine. It seems like issue with Ajax</p>