在Php4上的ajax Xajax

本文介绍如何利用Xajax框架快速实现网站的Ajax功能,通过简单的示例代码展示了页面元素的动态更新及颜色设置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公司要在三天内完成一个公司简介的网站
主要用于提升企业形象

中间用到了ajax技术

在网上搜了一会,打到了一个 Xajax 也是sourceforge的项目用起来很方便

下载后

Demo下载

按他的例子自己改了一点

 

helloword2.php

<?php

require ('Xajax024/xajax.inc.php');

function helloWorld($isCaps)
{
 if ($isCaps)
 {
  $text =file_get_contents('page1.html');
 }
 else
 {
  $text =file_get_contents('page2.html');
 }

 $objResponse = new xajaxResponse();
 $objResponse->addAssign("div2","innerHTML",$text);

 return $objResponse;
}

function setColor($sColor)
{
 $objResponse = new xajaxResponse();
 $objResponse->addAssign("div1","style.color", $sColor);

 return $objResponse;
}

// Instantiate the xajax object.  No parameters defaults requestURI to this page, method to POST, and debug to off
$xajax = new xajax();

//$xajax->debugOn(); // Uncomment this line to turn debugging on

// Specify the PHP functions to wrap. The JavaScript wrappers will be named xajax_functionname
$xajax->registerFunction("helloWorld");
$xajax->registerFunction("setColor");

// Process any requests.  Because our requestURI is the same as our html page,
// this must be called before any headers or HTML output have been sent
$xajax->processRequests();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>xajax example</title>
 <?php $xajax->printJavascript('Xajax024'); // output the xajax javascript. This must be called between the head tags ?>
 <style type="text/css" media="screen">
   body
   {
    background-color: #fff;
    color: #000;
    font: normal 0.8em tahoma, verdana, arial, serif;
    margin: 0;
    padding: 0;
   }

   #loading
   {
    background-color: #c00;
    border: 0.1em solid #800;
    color: #fff;
    display: none;
    margin: 0;
    right: 1em;
    padding: 0.25em 0.5em 0.25em 0.5em;
    position: absolute;
    bottom: 1em;
    width: 6em;
   }

  </style>
 <script language="javascript">
  function aa()
  {
   showLoading();
   xajax_helloWorld(0);
   hideLoading();
  }
  function showLoading()
  {
   document.body.style.cursor = 'wait';

   document.getElementById('loading').style.display = 'block';
  };

  function hideLoading()
  {
   document.body.style.cursor = '';

   document.getElementById('loading').style.display = 'none';
  };

 </script>
</head>
<body style="text-align:center;">

 <div id="loading">Loading...</div>
 <div id="div1" name="div1">xxx</div>

 <div id="div2" name="div2">xxx</div>
 <br/>

 <button onclick="aa();" >btn1</button>
 <button onclick="xajax_helloWorld(1)" >btn2</button>

 <button onclick="aa();" >btn3</button>

 <select id="colorselect" name="colorselect" onchange="xajax_setColor(document.getElementById('colorselect').value);">
  <option value="black" selected="selected">Black</option>
  <option value="red">Red</option>
  <option value="green">Green</option>
  <option value="blue">Blue</option>
 </select>
 <script type="text/javascript">
 xajax_helloWorld(0); // call the helloWorld function to populate the div on load
 xajax_setColor(document.getElementById('colorselect').value); // call the setColor function on load
 </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值