当前位置: 首页 > 图文教程 > 网络编程 > AJAX技术 > 实现一个基于Ajax的调查程序

AJAX技术
AJAX快速入门之HTTP协议基础
使用AJAX的十大理由
用Oracle JDeveloper 10.1.3构建Ajax应用程序
用AJAX+J2EE实现一个网上会议室系统
AJAX在VS2005中的简单应用
用AJAX编写一个简单的相册
利用AJAX技术提高搜索引擎排名
在ASP.NET中使用AJAX的简单方法
AJAX和Web开发新技术:Dynamic Faces
开发保留标准浏览器功能的AJAX应用程序
AJAX编程实践之与服务器通信
AJAX并不神秘:揭密各种AJAX控件和类库
使用AJAX技术构建更优秀的Web应用程序
使用GWT开发AJAX应用程序
为AJAX应用程序构建一个错误提交系统
总结AJAX相关JS代码片段和浏览器模型
全面剖析XMLHttpRequest对象
独立的思想 由AJAX应用引发的深思
一款经典的ajax登录页面 后台asp.net
ajax 调用后台方法大家可以讨论下

AJAX技术 中的 实现一个基于Ajax的调查程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 81 ::
收藏到网摘: n/a

<html>
<head>
<title>投票</title>
<META http-equiv=Content-Language content=zh-cn>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style type="text/CSS">
<!--
.poll {font-size: 10pt;display:block}
.pollresult {font-size: 12pt;display:none}
-->
</style>
<?php
 include_once("server1.server.php"); #servidor para XAJAX
 $xajax->printjavascript();
?>
</head>
<body>
<script language=javascript>
    function back() { 
      document.getElementById(’poll’).style.display = ’block’;
      document.getElementById(’pollresult’).style.display = ’none’;
      document.getElementById(’pollresult’).innerHTML = ’’;
    } 
</script>  
<div id=pollresult class=pollresult>
</div>

<?php

global $db;
$poll = $db->getRow("select * from TBL_POLL order by poll_id desc limit 1");
$poll_id = $poll["poll_id"];
$pollitems = $db->getAll("select * from TBL_POLLITEM where poll_id=$poll_id");
?>
<div id=poll class=poll>
<form id="pollForm" action="javascript:void(null);" onsubmit="onSubmit();"> 
   <?php echo $poll["title"]; ?><br>
   <?php for ($i = 0, $count = count($pollitems); $i < $count; $i++) { ?>
  <input type="radio" style="background-color : #CCCCCC;" name="pollitem" value="<?php echo $pollitems[$i][’pollitem_id’] ?>"><?php echo $pollitems[$i][’content’] ?><br>
  <?php } ?> 
  <input type="hidden" name="poll_id" value="<?php echo $poll_id; ?>">
  <input type="submit" value="enter">
</form> 
<script language=javascript>
    function onSubmit() { 
      xajax_poll(xajax.getFormValues("pollForm")); 
      document.getElementById(’poll’).style.display = ’none’;
      document.getElementById(’pollresult’).style.display = ’block’;
    } 
</script> 
</div>
</body>
</html> 
服务器端
function poll($formData){
  global $db;
  $tmp="";
  $objResponse = new xajaxResponse();
  
  $poll_id = $formData[’poll_id’];

  $pollitem_id = $formData[’pollitem’];
  
  if($pollitem_id > 0 && $poll_id > 0) { 
   $db->query("update ".TBL_POLLITEM." set count=count+1 where pollitem_id = $pollitem_id");                  
  }
  
  $poll = $db->getRow("select * from TBL_POLL where poll_id = $poll_id");
  $pollitems = $db->getAll("select * from TBL_POLLITEM where poll_id=$poll_id");
  
  
  $tmp&nbs