怎么在php中利用xml与Ajax实现一个点赞功能

  介绍

怎么在php中利用xml与Ajax实现一个点赞功能吗?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

一、准备好xml:

& lt; ? xml  version=?.0“?祝辞,   & lt; goodtree>,   ,,& lt; goodnode>   ,,,& lt; id> 0 & lt;/id>,   ,,,& lt; count> 17 & lt;/count>,   & lt;/goodnode>才能,   ,,& lt; goodnode>   ,,,& lt; id> 1 & lt;/id>,   ,,,& lt; count> 37 & lt;/count>,   & lt;/goodnode>才能,   ,,& lt; goodnode>   ,,,& lt; id> 2 & lt;/id>,   ,,,& lt; count> 67 & lt;/count>,   & lt;才能/goodnode>,,,   & lt;/goodtree>

其中ID只是用来看清楚排序的,没有实际的调用作用。

二,准备好HTML

& lt; div  ID=癵oodcount"比;   & lt;才能span> 0 & lt;/span> & lt; button  onclick=癵oodplus(0);“祝辞好+ 1 & lt;/button>   & lt;才能span> 0 & lt;/span> & lt; button  onclick=癵oodplus(1);“祝辞好+ 1 & lt;/button>   & lt;才能span> 0 & lt;/span> & lt; button  onclick=癵oodplus(2);“祝辞好+ 1 & lt;/button>   & lt;才能span> 0 & lt;/span> & lt; button  onclick=癵oodplus(3);“祝辞好+ 1 & lt;/button>   & lt;/div>

三,JAVASCRIPT包括Ajax在内,还添加了判断饼干的功能

var  span =, document.getElementsByTagName(& # 39;跨度# 39;),,   var  num,   var  flag =0;祝福;      (var 小姐:=,1;,小姐:& lt;, span.length  +, 1;,我+ +){,   ,,,senddata (i),,,,   },      function  goodplus (gindex) {,   ,,,flag =, 1,,   ,,,num =,方法(span.item (gindex) .innerHTML),,   ,,,如果(checkcookie (gindex),==, true) {,   ,,,,,num =, num  +, 1,,   ,,,,,senddata (gindex);,   还有,,,}{,   ,,,,,警报(“你已经点过赞咯!“),,,   ,,,},   },      function  senddata (aindex) {,   ,,,var  xmlhttp;,   ,,,var 三,,   ,,,如果(window.XMLHttpRequest) {,   ,,,,,xmlhttp=new  XMLHttpRequest (),,   还有,,,}{,   ,,,,,xmlhttp=new  ActiveXObject (“Microsoft.XMLHTTP");,   ,,,},   ,,,xmlhttp.onreadystatechange=function () {,   ,,,,,如果(xmlhttp.readyState ==, 4,,,, xmlhttp.status ==, 200) {,   ,,,,,,,如果(==flag  0) {,   ,,,,,,,,,xmldoc =, xmlhttp.responseXML;,   ,,,,,,,,,var  count =, xmldoc.getElementsByTagName(& # 39;计数# 39;),,   ,,,,,,,,,var  span2 =, document.getElementsByTagName(& # 39;跨度# 39;),,   ,,,,,,,,,,(var  j =, 0;, j  & lt;, count.length;, j + +) {,   ,,,,,,,,,,,span2.item (j) .innerHTML =,计算[j] . childnodes [0] .nodeValue;,   ,,,,,,,,,},   ,,,,,,,}else 如果(==flag  1) {,   ,,,,,,,,,xmldoc2 =, xmlhttp.responseText;,   ,,,,,,,,,var  span3 =, document.getElementsByTagName(& # 39;跨度# 39;),,   ,,,,,,,,,span3.item (aindex) .innerHTML =, xmldoc2;,   ,,,,,,,},   ,,,,,},   ,,,},   ,,,如果(==flag  0) {,   ,,,,,xmlhttp.open (“GET",“/ajax/foodmap/index.xml"),,   还有,,,}{,   ,,,,,xmlhttp.open (“GET"“/ajax/foodmap/index . php ? num=? +, num  +,“和aindex=? +, aindex,真的),,,,   ,,,},   ,,,xmlhttp.send (),,   },//判断是否已经存在了cookie    function  checkcookie (gindex) {,   ,,,var  thiscookie =, & # 39; sdcity_foodmap_goodplus& # 39;, +, gindex;,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在php中利用xml与Ajax实现一个点赞功能