无为清净楼资源网 Design By www.qnjia.com
终于到AJAX,翻译过来就是”异步Javascript和XML”,他可以实现网页内容的部分加载,可提高用户体验。现在有很多网站都有用这技术,反正你知道他能实现网页的异步更新就差不多了。当然下面的例子都相对简单,并没有体现它这一特点~
投票器
新建文件【 AJAX投票.html】
<html> <head> <script type="text/javascript"> // 这里是js代码 function getVote(int) { if (window.XMLHttpRequest) { // 创建 XMLHttpRequest 对象 // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码 xmlhttp = new XMLHttpRequest(); } else { //IE6, IE5 浏览器执行的代码 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } // 监听响应 xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState ==4 && xmlhttp.status == 200) { // 找到 id 为 poll 的控件 document.getElementById('poll').innerHTML = xmlhttp.responseText; } } // 向PHP脚本传递主要参数q xmlhttp.open("GET", "poll_vote.php" + int, true); xmlhttp.send(); } </script> </head> <body> <div id="poll"> <h3>你喜欢吃吗"radio" name="vote" value="0" onclick="getVote(this.value)"><br> 否:<input type="radio" name="vote" value="1" onclick="getVote(this.value)"> </form> </div> </body> </html>
创建【poll_vote.php】脚本文件
<"poll_result.txt"; $conn = file($filename); // 将数据分割到数组 $array = explode("||", $conn[0]); $yes = $array[0]; $no = $array[1]; $count = $array[2]; if ($vote == 0) { $yes += 1; $count += 1; } if ($vote == 1) { $no += 1; $count += 1; } // 将投票数据保存到文档 $insertvote = $yes . '||' . $no . '||' . $count; $fp = fopen($filename, "w"); fputs($fp, $insertvote); fclose($fp); "display: inline-block; background-color: green; width: <"></span><"display: inline-block; background-color: red; width: <"></span><"参与人数:" . $count; "text-align: center">
总结
以上所述是小编给大家介绍的PHP+AJAX 投票器功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
标签:
php,ajax,投票器
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】