通过html按钮回调调用服务器端的C函数

时间:2013-09-03 14:04:54

标签: php javascript jquery html ajax

我想在点击网站上的按钮后尝试调用用C / C ++编写的函数。例如,假设我有一个带有图像和按钮的网站;单击按钮后,我想运行一个可以执行一些过滤的C例程(可能是低通/模糊过滤器),然后使用模糊图像更新图像(最好不重新加载整个网站)。

我的理解是你不能直接在javascript中执行此操作,因为它在客户端运行。我知道你可以用PHP调用C函数,但我的理解是,在加载网站时解析/运行php,然后基本上完成了php(虽然这可能是错误的或不完整的)。

因此,我应该采用什么通用路径将此C函数称为按钮回调,让它在服务器上运行,然后返回并更新图像。如果可能的话,我想坚持使用主要语言,如php,javascript,jquery或AJAX,如果需要等等。

3 个答案:

答案 0 :(得分:4)

如果你知道如何从php调用你的c函数,那么你差不多完成了。

“无需重新加载整个网站”意味着使用AJAX。最简单的方法可能是使用JQuery.ajax来执行ajax请求,该请求从服务器获取结果然后将其放入页面。

答案 1 :(得分:3)

      Server               |        Client      
---------------------------------------
                           |   Client requests page
             /-------------+-------------/ 
PHP generates a GUI and    |
sends HTML/javascript to   |
client to tell browser what|
to display                 |
         \-----------------+---------\    
                           |        User uses GUI to issue a command
                           |        one that should run a server side action
                           |        an ajax request is sent to inform the server 
                           |        of the request 
    /----------------------+-----------/
Server recuieves an ajax   |
request, this tells the    |
server to run a command    |
The command is run and the |
server returns to the user |
updated data               |
   \-----------------------+--------------\
                           |    Updated data is recieve by the browser and capture as
                           |    a return on a ajax request. The image is updated as per
                           |    the users expectations.                       

答案 2 :(得分:0)

如果我需要这样做,我会使用node.js(javascript),并编写一个包含我的C函数的node.js插件,然后通过某种类型的rest API调用它:

http://www.nodejs.org/api/addons.html

相关问题