Run a PHP function upon button click?

前端 未结 8 1665
小鲜肉
小鲜肉 2021-01-03 04:24

I want to run a PHP function with an HTML button click.

I can call a PHP script this way:

Name
相关标签:
8条回答
  • 2021-01-03 04:46

    This is a little complicated. You can either submit the form to itself, check to see if the post variable is set (if it is, then the page is being run because the form was submitted to it), or you can use ajax. The first is an easier solution, and the second doesn't require a page reload. Pick your poison ;)

    Look at this for the first solution, and look at jquery's ajax functions for the second.

    0 讨论(0)
  • 2021-01-03 04:47

    This won't work. PHP is pretty much done processing by the time the user handles the page. You'd have to use AJAX to send the data to the server and retrieve the response.

    0 讨论(0)
提交回复
热议问题