<html>
<head>
<meta charset="UTF-8">
<title>登陆页面</title>
<link rel='stylesheet prefetch' href='https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel="stylesheet" href="css/style.css">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript">
function sub() {
var name = $("#name").val();
var password = $("#password").val();
//第二步:验证数据,这里需要从数据库调数据,我们就用到了ajax
$.ajax({
url: "/submit",//请求地址
data: {name: name, password: password},//提交的数据
type: "POST",//提交的方式
dataType: "TEXT", //返回类型 TEXT字符串 JSON XML
success: function (data) { // 校验返回内容,进行跳转
//开始之前要去空格,用trim()
if (data.trim() == "true") {
window.location.href = "/welcome?name=" + name;
}
else {
alert("用户名或者密码错误!");
}
},
error: function (xhr) {
// 失败输出HTTP状态码
alert("调用失败!HTTP状态码:" + xhr.status);
}
})
}
</script>
</head> <body>
<div class="wrapper">
<div class="form-signin">
<h2 class="form-signin-heading">请登陆</h2>
<input type="text" class="form-control" value="tom" name="name" id="name" placeholder="用户名" required=""
autofocus=""/>
<input type="password" class="form-control" value="123" name="password" id="password" placeholder="密码"
required=""/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe">记住我
<a href="infoSubmit.html" class="regsiter">注册</a>
</label>
<button type="submit" id="btn" class="btn btn-lg btn-primary btn-block" onclick="sub()">登陆</button>
</div>
</div>
</body> </html>

style.css

 body {
background: #eee !important;
} .wrapper {
margin-top: 80px;
margin-bottom: 80px;
} .form-signin {
max-width: 380px;
padding: 15px 35px 45px;
margin: 0 auto;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.1);
} .form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 30px;
} .form-signin .checkbox {
font-weight: normal;
} .form-signin .form-control {
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
} .form-signin .form-control:focus {
z-index:;
} .form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-left-radius:;
border-bottom-right-radius:;
} .form-signin input[type="password"] {
margin-bottom: 20px;
border-top-left-radius:;
border-top-right-radius:;
} .checkbox {
margin-left: 100px;
} .regsiter {
margin-left: 20px;
}

截图:

点击登陆按钮触发Ajax请求

Ajax之Jquery封装使用举例的更多相关文章

  1. Ajax之Jquery封装使用举例2(Json和JsonArray处理)

    本例主要使用ajax进行异步数据请求,并针对返回数据为json和jsonarray类型的数据处理. 本例中只有前端的代码,后端代码不是本文重点,故省略. 后端接口返回数据为: Json: {" ...

  2. 不借助jquery封装好的ajax,你能用js手写ajax框架吗

    不借助jquery封装好的ajax,你能手写ajax框架吗?最基础的ajax框架,一起来围观吧. .创建XMLHttpRequest对象 var xhr = new XMLHttpRequest(); ...

  3. jQuery Ajax 二次封装

    jQuery Ajax通用js封装 第一步:引入jQuery库 <script type="text/javascript" src="<%=path%> ...

  4. Jquery封装ajax

    Jquery封装ajax   Load方法     <!-- 将jquery.js导入进来 -->     <script type="text/javascript&qu ...

  5. 模仿JQuery封装ajax功能

    需求分析 因为有时候想提高性能,只需要一个ajax函数,不想引入较大的jq文件,尝试过axios,可是get方法不支持多层嵌套的json,post方式后台接收方式似乎要变..也许是我不太会用吧..其实 ...

  6. jQuery 封装的ajax

    jquery封装的ajax 具体操作: $.get(url  [,data]  [,fn回调函数]   [, dataType]); data:给服务器传递的数据,请求字符串 .json对象 都可以设 ...

  7. Jquery封装的ajax的使用过程发生的问题

    Jquery封装的ajax的使用过程发生的问题 今天在做项目的时候使用到了ajax来完成项目前后端数据交互,在之后发现在前端没有数据显示,而后端数据确实存在,在多次检查代码之后,发现代码并不存在问题, ...

  8. ajax的再次封装!(改进版) —— new与不 new 有啥区别?

    生命不息重构不止! 上一篇写了一下我对ajax的再次封装的方法,收到了很多有价值的回复,比如有童鞋建议用$.extend,一开始还以为要做成插件呢,后来才知道,原来这个东东还可以实现合并.省着自己再去 ...

  9. Ajax与Jquery题库

    一.    填空题 1.在JQuery中被誉为工厂函数的是 $() . 2.在jQuery中需要选取<div>元素里所有<a>元素的选择器是 $("div a&quo ...

随机推荐

  1. python装饰器(备忘)

    # 装饰器decorator def deco1(fun): def PRINT(*args,**kwargs): print('------deco1------') fun(*args,**kwa ...

  2. Python框架学习之Flask中的常用扩展包

    Flask框架是一个扩展性非常强的框架,所以导致它有非常多的扩展包.这些扩展包的功能都很强大.本节主要汇总一些常用的扩展包. 一. Flask-Script pip install flask-scr ...

  3. oracle 11G direct path read 很美也很伤人

    direct path read在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读 ...

  4. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String

    557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public: string reverseWords(string ...

  5. git创建新分支

    1.创建本地分支 git branch 分支名,例如:git branch 2.0.1.20120806 注:2.0.1.20120806是分支名称,可以随便定义.   2.切换本地分支 git ch ...

  6. NPOI生成excel并下载

    NPOI文件下载地址:http://npoi.codeplex.com/ 将文件直接引用至项目中即可,,,,, 虽然网上资料很多,但有可能并找不到自己想要的功能,今天闲的没事,所以就稍微整理了一个简单 ...

  7. centos7 关闭selinux

    关闭SeLinux 临时关闭:setenforce 0 永久关闭:vi /etc/selinux/config

  8. python第一章:简介与安装--小白博客

    Python简介 Python是一种计算机程序设计语言.是一种动态的.面向对象的脚本语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项 ...

  9. 全局关键字搜索:Element UI Table内容过滤\jQuery过滤器fastLiveFilter插件\BootstrapVue插件;

    ```html data:{ resultMaster: [], otableData:[], schfilter:'' } watch: { schfilter: function(val, old ...

  10. Vue2 实现树形菜单(多级菜单)功能模块

    结构示意图 ├── index.html ├── main.js ├── router │ └── index.js # 路由配置文件 ├── components # 组件目录 │ ├── App. ...