Run PHP function on html button click

前端 未结 6 1035
渐次进展
渐次进展 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:07

    If you want to make a server request you should use AJAX, so you can send your desired parameters to the server and it can run whatever php you want with these parameters.

    Example with pure javascript:

    
    
    
    

    Example with jQuery Ajax: http://api.jquery.com/jQuery.ajax/

    $.ajax({
      type: "POST",
      url: "some.php",
      data: { name: "John", location: "Boston" }
    }).done(function( msg ) {
      alert( "Data Saved: " + msg );
    });
    

    You can have one file with functions called for example functions.php

    functions.php

    
    

    some.php

    
    

提交回复
热议问题