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?
5条回答 默认 最新
duanna2026 2010-06-16 00:12关注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>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); } }); });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.
Hope that helps!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报