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
2017-02-01
赞id="zans{$r[id]}" title="$r[id]}">0
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)
phpajaxh5 implements the image upload function
phpajaximplements 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!