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

AJAX技术
Ajax内部交流文档
建立XMLHttpRequest对象
AJAX初体验之实战篇:打造博客无刷新搜索
掌握AJAX
AJAX聊天室V1.0发布
Ajax实现评论提交
PPJOKE 0.1 (网页嵌入聊天)提供下载
Ajax标签导航效果(仿网易首页)
ajax实现标签导航
琥珀无限级分类联动菜单AJAX版
结合AJAX进行PHP开发之入门
AJAX开发简略 (第二部分)
国内首发 -- ajax完整功能框架
AJAX初级聊天室代码
Ajax.基础教程 电子书版 提供下载
AjaxUI:鼠标拖拽
一个AJAX自动完成功能的js封装源码[支持中文]
Ajax读取XML实现动态下拉导航
强烈推荐-ajax开发者必看的文章
asp+Ajax简单客户登陆验证

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


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