本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)評(píng)論功能的具體代碼,供大家參考,具體內(nèi)容如下
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國(guó)際域名空間、虛擬空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、杭錦后網(wǎng)站維護(hù)、網(wǎng)站推廣。
前端
<textarea class='the_prw_in' bindinput='bindblur' cursor-spacing="130" placeholder='說(shuō)點(diǎn)什么吧...' maxlength="76"> </textarea> <view class='the_prw_btn' bindtap='btn_send'> 留言 </view> <view>評(píng)論內(nèi)容:</view> <block wx:for="{{pl_list}}" wx:key="index"> <view class='the_msg' wx:if='{{item.input_value!=null}}'> <!-- <view class='msg_left'> <view class='msg_avatar_v'> <image class='msg_avatar' src='{{msg_data.avatar}}'></image> </view> </view> --> <view class='msg_right'> <!-- <view class='msg_right_name'> {{msg_data.nicename}} </view> --> <view class='msg_right_text'> <text>{{item.input_value}}</text> </view> <view class='gap'> </view> </view> </view> </block>
js: 默認(rèn)展示歷史評(píng)論,評(píng)論后也刷新頁(yè)面,連帶此次評(píng)論內(nèi)容一起展示。
var bindblur ; Page({ bindblur:function(e){ console.log('1111111:', e.detail.value) bindblur = e.detail.value; }, onLoad: function (a) { var that = this; actid = a.id; // 查詢?cè)u(píng)論fetch wx.request({ url: 'https://m.yishushe.net/addons/up_text.php', method: 'POST', header: { 'content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, data: { act_id: actid }, success: function (result) { that.setData({ pl_list: result.data.reverse(), }) }, fail: res => { wx.showToast({ title: '網(wǎng)絡(luò)不好喲', image: '/image/wrong.png', duration: 3000 }) } }) }, btn_send: function () { var that = this //添加評(píng)論 console.log('文章id:act_id :', actid); console.log('用戶緩存id:user_id :', user_id); console.log('文本輸入框: input_value :', bindblur); wx.request({ url: 'https://m.yishushe.net/addons/up_text.php', method: 'POST', header: { 'content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, data: { act_id: actid, user_id: user_id, input_value: bindblur }, success: function (result) { that.setData({ pl_list: result.data.reverse(), input_value: "", }) }, fail: res => { wx.showToast({ title: '網(wǎng)絡(luò)不好喲', image: '/image/wrong.png', duration: 3000 }) } }) } })
后端php 源碼:
<?php header("Content-Type:text/html;charset=utf8"); header("Access-Control-Allow-Origin: *"); //解決跨域 header('Access-Control-Allow-Methods:POST');// 響應(yīng)類型 header('Access-Control-Allow-Headers:*'); // 響應(yīng)頭設(shè)置 $link=MySQL_connect("localhost","root","root"); mysql_select_db("weiqing", $link); //選擇數(shù)據(jù)庫(kù) mysql_query("SET NAMES utf8");//解決中文亂碼問(wèn)題 //$username = $_POST['username']; //$avatarUrl = $_POST['avatarUrl']; $act_id = $_POST['act_id']; if($_POST['input_value']){ $user_id = $_POST['user_id']; $input_value = $_POST['input_value']; //echo $avatarUrl."----time:". $time."----iv:".$iv."----inputValue:". $inputValue; //插入數(shù)據(jù)到數(shù)據(jù)庫(kù) $strsql = "insert into pinglun (act_id,user_id,input_value) values('$act_id','$user_id','$input_value')"; //mysql_query() 函數(shù)執(zhí)行一條 MySQL 查詢。SELECT,SHOW,EXPLAIN 或 DESCRIBE 都需要用這個(gè)函數(shù)執(zhí)行 $result = @mysql_query($strsql); } $q = "SELECT * FROM pinglun"; //SQL查詢語(yǔ)句 SELECT * FROM 表名 $rs = mysql_query($q); //獲取數(shù)據(jù)集 if(!$rs){die("數(shù)據(jù)庫(kù)沒有數(shù)據(jù)!");} //循環(huán)讀取數(shù)據(jù)并存入數(shù)組對(duì)象 $dlogs;$i=0; while($row=mysql_fetch_array($rs)) { if($act_id ==$row["act_id"]){ $dlog["act_id"]=$row["act_id"]; $dlog["user_id"]=$row["user_id"]; $dlog["input_value"]=$row["input_value"]; } //$dlog["avatarUrl"]=$row["avatarUrl"]; //$dlog["username"]=$row["username"]; $dlogs[$i++]=$dlog; } //以json格式返回html頁(yè)面 echo urldecode(json_encode($dlogs)); ?>
如果php返回報(bào)錯(cuò)就找到php-ini 配置文件 ,把
display_errors = On
改為
display_errors = Off
禁止php報(bào)錯(cuò)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
文章標(biāo)題:微信小程序?qū)崿F(xiàn)評(píng)論功能
網(wǎng)站網(wǎng)址:http://muchs.cn/article34/jehpse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、網(wǎng)站排名、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)