Do not refresh the page on PHP

综合技术 2017-11-15 阅读原文

I would like to achieve that when I click on submit button, it doesn't refresh the page. My submit button only calls set of codes if is submitted. But when it is submitted, it refreshes the page and my variables lose its values.

I know this can be achieved with java-script or ajax but this is where I have no knowledge yet. Need to start learning it. I have tried to use some other suggestion with JavaScript but it didn't work for me as the JavaScript code was build for most advance form not only one submit button.

My Button:

";

My code which executes when submit button is pressed:

if(isset(&_POST['confirm_points'])) {
    // my code is here
}

Thanks for any help

Here's a simple example:




    
    
        $(document).ready(function(){
            $('form').submit(function(event){
                event.preventDefault();
                $.ajax({
                    type: $(this).attr('method'),
                    data: $('form').serialize(),
                    success: function(data) {
                        $('#result').html(data);
                    }
                });
            });
        });
    



Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!