AJAX – form submit, same page, PHP

You need to prevent the JS from submitting the form, and you’re using the wrong form ID. Also, judging by the comments, you need to include jquery.

In the head of your HTML file, between <head> and </head> or just before the closing </body> tag, you can use the following:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

The following code may help you (though it’s advised to not query the same page as your ajax request emits from):

<script type="text/javascript">
$(function(){
    $('button[type=submit]').click(function(e){

    e.preventDefault();

        $.ajax({
            type: "POST",
            url: "match_details.php",
            data: $("#match_details").serialize(),
            beforeSend: function(){
                $('#result');
            },
            success: function(data){
                $('#result').html(data);
            }
        });
    });
});
</script>

Leave a Comment