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

AJAX技术
5款Ajax 文件上传控件
使用jQuery简化Ajax开发
ajax 异步获取数据实现代码 (js创建ajax对象)
AJAX 用户唯一性验证实现代码
ajax+php 谷歌搜索框自动填充功能 实例代码
ajax 同步和异步XMLHTTP代码分析
AJAX 动态获取当前时间(php)
AJAX 实时读取输入文本(php)
AJAX 二级级联菜单实现代码
利用AJAX实现鼠标悬浮获取值的代码
javascript ajax功能函数
javascript对XMLHttpRequest异步请求的面向对象封装
一个AJAX类代码
AJAX在GB2312的中文编码传输 AJAX特殊字符编码正确方法
编码为GB2312网站让AJAX接收的数据显示支持中文
ajax实现的提交文章前进行敏感词审核的代码
js+AJAX异步从优酷专辑中采集所有视频及信息
ajax 缓存 问题 requestheader
十大最佳Ajax教程收集(图文)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 74 ::
收藏到网摘: 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