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

AJAX技术
AJAX初级应用-RSS无刷新聚合器的代码与下载
一个封装的Ajax类
pjblog发表评论用的ajaxJS.js
AJAX和JSP实现的基于WEB的文件上传的进度控制代码
AJAX实现仿Google Suggest效果
Baidu Musicbox 用到的ajax代码
[asp]天枫AJAX百度音乐即时听附下载
[asp]天枫AJAX blog V1.0 程序提供下载了
ajax+asp无限级分类树型结构的代码
asp+ajax实现静态页面分页的代码
用ajax实现在单击事件下加载一个DIV层的脚本
AJAX javascript的跨域访问执行
javascript 拖动_cookie_ajax等
Ajax象棋演示和并提供代码下载
仿google搜索提示 SuggestFramework的使用
利用AJAX开源项目 在网页里播放视频实现方法
ajax 服务器文本框自动填值
ajax 数据库中随机读取5条数据动态在页面中刷新
asp.net 全部选中与取消操作,选中后的删除(ajax)实现无刷新效果
javascript Ajax 类实现代码

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


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