Do not refresh the page on PHP

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!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Do not refresh the page on PHP

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录