How can I call PHP functions by JavaScript?

后端 未结 11 1210
情话喂你
情话喂你 2020-11-22 12:08

I am trying to call a PHP function from an external PHP file into a JavaScript script. My code is different and large, so I am writing a sample code here.

This is m

11条回答
  •  醉酒成梦
    2020-11-22 12:54

    You need to create an API : Your js functions execute AJAX requests on your web service

      var mult = function(arg1, arg2)
        $.ajax({
          url: "webservice.php?action=mult&arg1="+arg1+"&arg2="+arg2
        }).done(function(data) {
          console.log(data);
        });
      }
    

    on the php side, you'll have to check the action parameter in order to execute the propre function (basically a switch statement on the $_GET["action"] variable)

提交回复
热议问题