开发者

Server command via AJAX interface

I'm new on AJAX. Just for fun I'm trying to control开发者_开发知识库 my sever via an AJAX interface. It's quite easy, for instance in PHP, to send a command to the server by the system() function and just a text field and a submit button.

The thing I'd like to do is to control in realtime some action, for example controlling music volume by a web interface, with a simple slide without any submit button.

Don't care about the way to control volume, is just a piece of example, imagine it like a php system() function.

WELL the question is: How can I implement such a remote control system**?** (The server is the machine that in this single case hosts the webserver).


Have you already tried to do the control with a PHP only webinterface (e.g. reading requests like http://server/control.php?volume=10 or http://server/control.php?jumpToPercent=30)?

From there you can Ajaxify it partially e.g. by sending your form submits asynchronously via Ajax (recommending the jQuery form plugin). If you want to use a slider you could use the jQuery UI slider, which sends a request like

$.getJSON('http://server/control.php', { jumpToPercent : $(slider).percentValue() },
    function(data) { $(slider).value(data.value); }, 'json');

whenever it is changed (read the documentation for the correct events and invocations) and your PHP script changes the position and returns e.g.

{ "value" : 50 }

which is the new actual position of the slider.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜