Change content of a div on another page

前端 未结 4 616
温柔的废话
温柔的废话 2021-01-24 06:52

On page 1, I have a div containing information.

And on page 2, I have a form

4条回答
  •  执笔经年
    2021-01-24 07:20

    Hope this will give you an idea of how you can do it:

    Page 2

    HTML

    JS

    $("form").submit(function(e){
    
        e.preventDefault();
    
        $.post('save_data.php', { new_info:$("#new-info").val() }).done(function(data){
             // Do something if you want to show that form has been sent
        });
    
    
    });
    

    save_data.php

    
    

    Page 1

    HTML

    JS

    setInterval(search_after_info, 1000);
    
    
    function search_after_info() {
    
        $.get('get_data', function(data) {
    
            $("#information").html(data);
    
        });
    
    }
    

提交回复
热议问题