How to call a php script/function on a html button click

后端 未结 7 2057
南旧
南旧 2020-11-27 19:20

Before someone has a go at me or marks this down, I have looked all over the internet to find out how to do this (including the same question on stackoverflow). I\'m new, an

7条回答
  •  伪装坚强ぢ
    2020-11-27 19:47

    You can also use

       $(document).ready(function() {
    
        //some even that will run ajax request - for example click on a button
    
        var uname = $('#username').val();
        $.ajax({
        type: 'POST',
        url: 'func.php', //this should be url to your PHP file
        dataType: 'html',
        data: {func: 'toptable', user_id: uname},
        beforeSend: function() {
            $('#right').html('checking');
        },
        complete: function() {},
        success: function(html) {
            $('#right').html(html);
        }
        });
    
        });
    And your func.php:
    
      function toptable()
     {
      echo 'something happens in here';
     }
    

    Hope it helps somebody

提交回复
热议问题