How to call a JavaScript function from PHP?

后端 未结 10 2389
误落风尘
误落风尘 2020-11-21 23:03

How to call a JavaScript function from PHP?

The followi

10条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 23:32

    You may not be able to directly do this, but the Xajax library is pretty close to what you want. I will demonstrate with an example. Here's a button on a webpage:

     
    

    Our intuitive guess would be that xajax_addCity() is a Javascript function, right? Well, right and wrong. The cool thing Xajax allows is that we don't have any JS function called xajax_addCity(), but what we do have is a PHP function called addCity() that can do whatever PHP does!

    
    

    Think about it for a minute. We are virtually invoking a PHP function from Javascript code! That over-simplified example was just to whet the appetite, a better explanation is on the Xajax site, have fun!

提交回复
热议问题