Home > Web Front-end > JS Tutorial > body text

Ajax implements phpcms like function (graphic tutorial)

亚连
Release: 2018-05-22 16:14:15
Original
1958 people have browsed it

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}
Copy after login

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>
Copy after login

ajax processing K=8 is likes

$(".zanbtn").on("click",function(){ 
                var id = $(this).next().attr("title"); 
                var aval = $(this).next("a").html(); 
                $.getJSON(&#39;http://phpcms.com/index.php?m=mood&c=index&a=post&id=150-&#39;+id+&#39;-1&k=8&&#39;+Math.random()+&#39;&callback=?&#39;, function(data){ 
                  if(data.status==1) { 
                    console.log( $(this).next()); 
                    $("#zans"+id).html(data.data); 
                  }else { 
                    alert(data.data);   
                    return false;       
                  } 
                }) 
              });
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template