Run PHP function on html button click

前端 未结 6 1037
渐次进展
渐次进展 2021-01-31 00:43

I need to run some PHP function when a button is clicked. I know this is not supposed to be php\'s use, rather js should do it, but what my functions are doing in gathering data

6条回答
  •  日久生厌
    2021-01-31 01:09

    Use ajax, a simple example,

    HTML

    
    

    Javascript

    var button = document.getElementById("button");
    
    button.addEventListener("click" ajaxFunction, false);
    
    var ajaxFunction = function () {
        // ajax code here
    }
    

    Alternatively look into jquery ajax http://api.jquery.com/jQuery.ajax/

提交回复
热议问题