Home > Article > Web Front-end > Ajax implements phpcms like function (graphic tutorial)
This article mainly introduces the example code of Ajax implementation of phpcms like function. It is very good and has reference value. Friends who need it can refer to it
First, add the module in the background--->News Mood--->Mood configuration Remove the redundant one and change the name to "Like" Submit and save.
The second is the template file to modify the news mood:/phpcms/templates/default/mood/index.html
Delete all codes and only return the total number of likes
{loop $setting $k $v} {$data[$v['fields']]} {/loop}
The implementation of the template page is as follows. Through the loop array
<p class="info"> <a href="http://phpcms.com/content-150-1-1.html" target="_blank" title="展会现场人头攒动"><h4 class="title ellipsis download">展会现场人头攒动</h4></a> <p class="date">2017-02-01</p> <p class="sum"> <span class="laud"><i class="iconfont zanbtn" >赞</i><a href="javascript:;" rel="external nofollow" <span style="min-width: 0px; min-height: 0px; box-sizing: border-box; color: rgb(34, 34, 34); unicode-bidi: -webkit-isolate; font-family: Consolas, "Lucida Console", monospace; white-space: pre-wrap;">id</span><span style="color: rgb(34, 34, 34); font-family: Consolas, "Lucida Console", monospace; white-space: pre-wrap;">="</span><span style="min-width: 0px; min-height: 0px; box-sizing: border-box; color: rgb(34, 34, 34); unicode-bidi: -webkit-isolate; font-family: Consolas, "Lucida Console", monospace; white-space: pre-wrap;">zans{$r[id]}</span><span style="color: rgb(34, 34, 34); font-family: Consolas, "Lucida Console", monospace; white-space: pre-wrap;">" </span> title="<span style="color: rgb(34, 34, 34); font-family: Consolas, "Lucida Console", monospace; white-space: pre-wrap;">$r[id]}</span>">0</a></span> </p> </p>
ajax processing K=8 is likes
$(".zanbtn").on("click",function(){ var id = $(this).next().attr("title"); var aval = $(this).next("a").html(); $.getJSON('http://phpcms.com/index.php?m=mood&c=index&a=post&id=150-'+id+'-1&k=8&'+Math.random()+'&callback=?', function(data){ if(data.status==1) { console.log( $(this).next()); $("#zans"+id).html(data.data); }else { alert(data.data); return false; } }) });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed analysis of how to use AJAX (code pasted)
php ajax h5 implements the image upload function
php ajaximplements the query drop-down content function
The above is the detailed content of Ajax implements phpcms like function (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!