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

后端 未结 7 2050
南旧
南旧 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:37

    First understand that you have three languages working together.
    

    PHP: Is only run by the server and responds to requests like clicking on a link (GET) or submitting a form (POST). HTML & Javascript: Is only run in someone's browser (excluding NodeJS) I'm assuming your file looks something like:

    
      
     Run PHP Function
     
    

    Because PHP only responds to requests (GET, POST, PUT, PATCH, and DELETE via $_REQUEST) this is how you have to run a php function even though their in the same file. This gives you a level of security, "Should I run this script for this user or not?".

    If you don't want to refresh the page you can make a request to PHP without refreshing via a method called Asynchronous Javascript and XML (AJAX).

提交回复
热议问题