需要一个按钮来调用一个PHP函数

需要一个按钮来调用一个PHP函数

问题描述:

我需要有一个按钮,调用PHP函数从DB诉诸显示的数据。如何赫克我做到这一点?我刚刚发现,由于PHP是服务器端的这个吸。因此,任何帮助吗?

I need to have a button that calls a php function to resort displayed data from the db. How the heck do I do this? I just found out that because php is server side this sucks. So any help please?

这是阿贾克斯工作,为他人提及。如果我可以详细说明,如果你开始,我强烈建议使用一个JavaScript库,使您的生活更轻松。随着原型,这里是你的按钮看起来是这样的:

This is a job for ajax, as others mentioned. If I may elaborate, if you're starting out, I HIGHLY recommend using a javascript library to make your life easier. With prototype, here's what your button might look like:

<input type="button" id="button_foo">Button</input>

下面就是你的JavaScript可能看起来像:

Here's what your javascript might look like:

$('button_foo').observe('mousedown',function(e){
    new Ajax.Request('handler.php',{
        method:'post',
        onSuccess:function(t){
            $('table_bar').update(t.responseText);
            }
    });
});

这初看起来有点吓人,但我认为基本的js使用库时有pretty管理的学习曲线。以上code将采取一切handler.php输出,并用返回的HTML替换table_bar与元素和id的内容。

This may seem a little daunting at first, but I think basic js has a pretty manageable learning curve when using a library. The above code would take whatever handler.php outputs, and replace the contents of an element with and id of "table_bar" with the returned html.

如果你决定使用原型,该文档是真正有用的,易于理解,并且有一个真正优秀的书上会让你很快理解它的主题务实preSS。

if you do decide to use prototype, the docs are really helpful and easy to understand, and there is a really excellent book by pragmatic press on the subject that'll have you understanding it very quickly.

希望帮助!