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! (源链)。感谢您的支持!

您可能感兴趣的

精读《2017前端性能优化备忘录》 本期精读的文章是: Front End Performance Checklist 2017 现在随着 web 应用的复杂性日益增加,其...
Is PHP relevant? One of the most common questions I’m asked by academees, applicants and even oth...
前端页面实现报警器提示音效果 原型图: 图片.png 项目需求:服务器接受到报警后将消息推送到前台,(通过前端实时消息提示的效果-websocket长轮询),前...
Zero to account takeover: How I ‘Impersonated’ Som... There’s a fine line between an unintended use and a bug; this was my conclusi...
URL Renaming via JavaScript I’m developing a website based on this tutorial and would ...