HTML onkeyup事件属性来运行PHP函数


HTML onkeyup Event Attribute to Run PHP Function

HTML onkeyup事件属性是否可以运行PHP函数而不是Javascript函数?

如果没有,那么是否可以立即让javascript函数调用PHP函数?

谢谢。

Kinda。。。您可以让onkeyup事件进行ajax调用,该调用将运行php脚本并返回值/object/等。

如果您使用的是jQuery,您可以查看文档来调用

示例代码为:

$(document).on('keyup', function () {
  $.ajax('http://www.domain.com/file.php')
      .done(function(data) {
         // javascript to run on success
      }
});

客户端可以触发event,以触发对执行PHP服务器的调用。

我会用图表来解释,这样你就可以更清楚地看到

[Client] (browser with javascript) does something
 -> event is triggered
    -> ajax request is sent to server
[Server] (that runs php scripts) receives request
 -> looks for the script to run
    -> if found, runs script
       -> output is returned to client
[Client] receives response
 -> client does something with response

正如你所看到的,这些技术存在于完全不同的环境中,托管在许多有助于透明通信的协议后面

可以模拟对php函数的调用

请阅读以下主题的

  • URL重写(您可以调用like http://host/phpfunc/param1/param2/paramN
  • javascript(它做什么和不做什么)
  • ajax(对服务器的异步调用)
  • jquery(一个很好的帮助库)