需要一个调用php函数的按钮 [英] need a button that calls a php function

查看:115
本文介绍了需要一个调用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?

推荐答案

这是一个像其他人提到的ajax的工作。如果我可以详细说明,如果你开始,我强烈推荐使用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有一个很容易管理的学习曲线使用库。上面的代码将接受任何handler.php输出,并用返回的html替换元素的内容和id为table_bar。

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.

如果你决定使用原型,文档是真正有用的和易于理解,并有一本真正优秀的书由务实的新闻对主题,将让你很快理解它。

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.

希望有所帮助!

这篇关于需要一个调用php函数的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆