你的位置:HBcms宏博内容管理系统 PHP技术 正文
PHP技术
  1. 专用主机
内容搜索
热门内容
  1. PHP官方网站,php官方..
  2. 建网站需要多少钱? 建..
  3. PHP ASP比较:PHP比AS..
  4. PHP6下载,php6介绍和..
  5. php程序员前途,mysql..
  6. 宏博cms和北京易体验合..
  7. SMTP判断邮箱是否存在..
  8. PHP生成静态页面详解
  9. 用PHP与XML进行网站编..
  10. 美国Hostmonster虚拟主..
推荐内容
  1. PHP官方网站,php官方..
  2. 把握商机:免费成为 H..
  3. 用PHP与XML进行网站编..
  4. [转]PHP突出开源优势要..
  5. 在线操作系统----TOMO..
  6. 用PHP实现验证码功能
  7. PHP生成静态页面详解
  8. 宏博cms和北京易体验合..
  9. Linux服务器php虚拟主..
  10. php程序员前途,mysql..
PHP的PEAR::HTML_AJAX类库应用
  • 原作者:hbcms 添加时间:2007-05-26 发表时间:2007-05-26 人气:1876
  • 本文章共6540字,分2页,当前第1页,快速翻页:
  • PHP的PEAR::HTML_AJAX类库应用

    HTML_AJAX下载http://pear.php.net/package/HTML_AJAX/download

    Pear:HTML_AJAX是一个相当成熟的Ajax框架, 使用JSON进行数据传输。內建丰富的例子,包括留言板、登录、grab…等等。

    简单的例子:

    Setting up a server

    You can use HTML_AJAX in many different ways but most setups use an instance of HTML_AJAX_Server to deliver both the javascript libraries and to handle AJAX requests from browsers.

    A basic server is shown below, in the file server.php:

    
    <?php
    //a session is required(you can also set session.auto_start=1 in php.ini)
    session_start();
    
    include 'HTML/AJAX/Server.php';
    
    $server = new HTML_AJAX_Server();
    $server->handleRequest();
    ?>
    

    This basic setup gives you access to the HTML_AJAX javascript libraries, which will allow you to do basic AJAX actions like replacing the content of a div with the output of a url on your server.

    Let us now create a new webpage with a div container and a button. Whenever we push the button we want to fetch some data and update the div container. Save the file as page.html:

    <html>
    
    <script type="text/javascript" src="server.php?client=all"></script>
    <div id="target">I'm the target</div>
    <script type="text/javascript">
    HTML_AJAX.replace('target','output.php');
    </script>
       <form>
          <input type="button" onclick="HTML_AJAX.replace('target','output.php');" value="Update target">
       </form>
    </html>

    This will load the content of output.php into the <div> with an ID of "target" when HTML_AJAX.replace() is called (i.e. when you push the button).

    Now let's create the file that generates the dynamic stuff. It could be anything, like fetching stuff from a database or whatever. For now we are going to get the local time, and we do it in the file output.php:

    
    <?php
    
       print("<h1>". strftime("%H:%M:%S") ."</h1>");
    ?>
    

    There! Each time you press Update target, the target is replaced with the current time. Now it's up to your imagination to use this to something more useful.

  • 点这里复制本页地址发送给您QQ/MSN上的好友
  • 相关文章
  • 相关评论
  • 本文章所属分类:首页 PHP技术