我有一個可用的 PHP Ajax 投票系統(tǒng),可以將博客文章中的贊寫入 .txt 文件,我想將其擴(kuò)展為多個帖子并記錄每個帖子的贊。我試圖更改“onclick”值,但似乎我使用的腳本限制了我。HTML<span id="like"><a href="javascript:" name="vote"value="0" onclick="getVote(this.value)">Like</a></span>爪哇腳本function getVote(int){ if(window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest() }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } xmlhttp.onreadystatechange=function({ if(this.readyState==4&&this.status==200{ document.getElementById("like").innerHTML=this.responseText } }; xmlhttp.open("GET","vote.php?vote="+int,true); xmlhttp.send()}PHP<?php $vote=$_REQUEST['vote'];$filename="votes.txt";$content=file($filename);$array=explode("-",$content[0]);$yes=$array[0];if($vote==0){ $yes=$yes+1;}$insertvote=$yes;$fp=fopen($filename,"w");fputs($fp,$insertvote);fclose($fp);?>我是否應(yīng)該為每個想要保存喜歡的帖子編寫不同的 .php 文件?
多個帖子的 PHP 投票系統(tǒng)
慕運(yùn)維8079593
2021-11-26 15:18:22