thinkcmf本身自带的form提交需要跳转成功页面,体验太差,用ajax提交就比较可控了
<div class="hbf_btn" data-src="{:U('api/guestbook/addmsg')}">提交评价</div>
/**js部分**/
$(".home").on("click",".hbf_btn",function(){
let href = $(this).attr("data-src");
let name = $(".hb_list ul li.on").attr("data-name");
let type = $(".hbf_select ul li.on").attr("data-type");
let msg = $(".hb_form .hbf_text textarea").val();
$.ajax({
type: 'post',
url: href,
data: {full_name:name,email:type,msg:msg},
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(data){
mui.toast("系统错误,请重新操作!!!");
location.reload();
}
})
})
‘{:U('api/guestbook/addmsg')}’为form提交的action,提交的参数data可根据数据库字段进行增删改,后台调用对应修改就OK
同时使用ajax需去掉留言模块在控制器里面的验证,位置如下