这节我们继续优化,接收到返回值,我们在前端做一些处理,如:密码修改成功,弹出一个成功的提示框。这个提示框我们采用sweetalert

其中xtalert.js是对上面两个文件的一个封装,使得我们用sweetalert变得更简单,需要素材的同学点击右侧的二维码打赏10元,截图发送到邮箱463951510@qq.com吧,之前打赏过本论坛实战的就不用再打赏了哈!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="sweetalert/sweetalert.css">
<script src="sweetalert/sweetalert.min.js"></script>
<script src="sweetalert/xtalert.js"></script>
<style>
button{
display: block;
margin-bottom: 10px;
}
</style>
</head>
<body>
<button onclick="xtalert.alertError('不能删除文章!')">错误提示</button>
<button onclick="xtalert.alertInfo('您没有权限,请联系管理员!')">信息提示</button>
<button onclick="xtalert.alertSuccess('恭喜您!操作成功!')">成功提示</button>
<button id='confirm-btn'>确认提示</button>
<script>
var confirmBtn = document.getElementById('confirm-btn');
confirmBtn.onclick = function(event){
xtalert.alertConfirm({
'msg': '恭喜!文章发表成功!是否再发一篇?',
'confirmText': '再发一篇',
'cancelText': '回到首页',
'confirmCallback': function(){
alert('点击了确认按钮');
},
'cancelCallback': function(){
alert('点击了取消按钮');
}
});
}
</script>
<button id='input-btn'>输入框提示</button>
<script>
var inputBtn = document.getElementById('input-btn');
inputBtn.onclick = function(event){
xtalert.alertOneInput({
'text': '请输入板块名称',
'confirmCallback': function(text){
alert(text);
xtalert.close();
}
});
}
</script>
<button onclick="xtalert.alertNetworkError()">网络错误</button>
<button onclick="xtalert.alertInfoToast('权限受限,请联系管理员!')">信息toast</button>
<button onclick="xtalert.alertErrorToast('权限受限,请联系管理员!')">错误toast</button>
<button onclick="xtalert.alertSuccessToast('恭喜!操作成功!')">成功toast</button> </body>
</html>

sweetalert提示框使用demo

在 static/common/下创建目录sweetalert,并把以上3个文件放进去,因为不仅仅修改密码会用到提示框,项目其他地方也会用到,所以把它放到common里面。

在父模板cms_base.html引入此3个文件

<head>
...
<link href="{{ url_for('static', filename='common/sweetalert/sweetalert.css')}}" rel="stylesheet">
<script src="{{ url_for('static', filename='common/sweetalert/sweetalert.min.js') }}"></script>
<script src="{{ url_for('static', filename='common/sweetalert/xtalert.js') }}"></script>
</head>

现在就可以修改resetpwd.js,对返回值做处理了

/**
* Created by user on 2018/8/7.
*/ $(function () {
$('#submit').click(function (event) {
//阻止按钮默认的提交表单行为
event.preventDefault();
var oldpwdE = $('input[name=oldpwd]');
var newpwdE = $('input[name=newpwd]');
var newpwd2E = $('input[name=newpwd2]'); var oldpwd = oldpwdE.val();
var newpwd = newpwdE.val();
var newpwd2 = newpwd2E.val(); //这里使用我们自己封装好的bbsajax,它具有了csrf
bbsajax.post({
'url': '/cms/resetpwd/',
'data': {
'oldpwd': oldpwd,
'newpwd': newpwd,
'newpwd2': newpwd2
},
'success': function (data) {
//根据状态码判断
if (data['code'] === 200){
//弹出成功的提示框,提示语是从后台传过来的message
xtalert.alertSuccessToast(data['message']);
oldpwdE.val(''); //完成请求后把表单输入的值清空
newpwdE.val('');
newpwd2E.val('');
}else{
xtalert.alertError(data['message']);
oldpwdE.val('');
newpwdE.val('');
newpwd2E.val('');
}
},
'fail': function (error) {
xtalert.alertNetworkError('网络错误');
}
});
});
})

33、Flask实战第33天:sweetalert提示框的更多相关文章

  1. sweetalert提示框

    文档 sweetalert Api:http://t4t5.github.io/sweetalert/ 开源项目源码:https://github.com/t4t5/sweetalert 在文件中首先 ...

  2. 「小程序JAVA实战」小程序 loading 提示框与页面跳转(37)

    转自:https://idig8.com/2018/09/02/xiaochengxujavashizhanxiaochengxu-loading-tishikuangyuyemiantiaozhua ...

  3. 一百零二:CMS系统之sweetalert提示框和使用

    实现效果 css body.stop-scrolling { height: 100%; overflow: hidden; } .sweet-overlay { background-color: ...

  4. 一百零三:CMS系统之使用sweetalert提示框优化返回结果

    在base模板中引用 在修改密码的js中使用 $(function () { $('#submit').click(function (evnet) { evnet.preventDefault(); ...

  5. 提示框插件SweetAlert

    SweetAlert可以替代Javascript原生的alert和confirm等函数呈现的弹出提示框, 它将提示框进行了美化,并且允许自定义, 支持设置提示框标题.提示类型.内容展示图片.确认取消按 ...

  6. The authenticity of host '172.16.33.53 (172.16.33.53)' can't be established的问题(日志六)

    用ssh登录一个机器(换过ip地址)会出现如下错误 weiguohui@weiguohui1-virtual-machine:~/.ssh$ ssh 172.16.33.53The authentic ...

  7. 漂亮的提示框SweetAlert使用教程

    一.简介 所使用过的弹出框插件,SweetAlert是最好用的.发展至今,已经有两个版本,一个是原版 t4t5/sweetalert , 一个是分支版 limonte/sweetalert2 ,更新相 ...

  8. Flask实战-留言板-安装虚拟环境、使用包组织代码

    Flask实战 留言板 创建项目目录messageboard,从GreyLi的代码中把Pipfile和Pipfile.lock文件拷贝过来,这两个文件中定义了虚拟环境中需要安装的包的信息和位置,进入m ...

  9. JS组件Bootstrap实现弹出框和提示框效果代码

    这篇文章主要介绍了JS组件Bootstrap实现弹出框和提示框效果代码,对弹出框和提示框感兴趣的小伙伴们可以参考一下 前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编 ...

随机推荐

  1. 常见的Shell

    上面提到过,Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本. Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等,习惯上把它们称作一种Shell.我们常说 ...

  2. 【BZOJ4540】【HNOI2016】序列 [莫队][RMQ]

    序列 Time Limit: 20 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 给定长度为n的序列:a1,a2,…,a ...

  3. 省队集训 Day4 a

    [题目大意] 求有多少区间只包含1个出现次数为1的数. $1\leq n \leq 5*10^5, 0 \leq a_i \leq 10^9$ [题解] 考虑枚举右端点,设这个数上一次出现位置为pre ...

  4. 【BZOJ】1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

    [题意]给定n头牛,k个特色,给出每头牛拥有哪些特色的二进制对应数字,[i,j]平衡当且仅当第i~j头牛的所有特色数量都相等,求最长区间长度. [算法]平衡树+数学转化 [题解]统计前缀和sum[i] ...

  5. chrome最小字体12px如何修改

    在html标记样式里加入 <style> html { -webkit-text-size-adjust:none } </style> 这样的方式可以设置chrome字体小于 ...

  6. Perl6 Bailador框架(4):路径匹配

    use v6; use Bailador; =begin pod /:one/:two/:....路径选择 这个路径, 用/分隔 每个/分隔一个, 如果你只设置两个(/admin/login),时, ...

  7. bisai.py

    比赛专用py #!/usr/etc/env python #encoding:utf-8 #by i3ekr #token import re,os,requests res = "(fla ...

  8. Caffe学习笔记2

    Caffe学习笔记2-用一个预训练模型提取特征 本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hi ...

  9. 64_g6

    gsettings-desktop-schemas-devel-3.24.0-1.fc26.x..> 22-Mar-2017 20:46 19386 gsf-sharp-0.8.1-27.fc2 ...

  10. python设计模式之单例模式(一)

    单例设计模式的概念: 单例设计模式即确保类有且只有一个特定类型的对象,并提供全局访问点.一般我们操作数据库的时候为了避免统一资源产生互相冲突,创建单例模式可以维护数据的唯一性. 单例模式的特性: 确保 ...