<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.mian {
box-sizing: border-box;
width: 800px;
height: auto;
min-height: 200px;
border: 5px solid gray;
border-radius: 20px;
background: lightgray;
margin: 0 auto;
line-height: 30px;
}
.search, .create {
width: 600px;
min-height: 50px;
height: auto;
margin: 0 auto;
}
.create {
margin-top: 20px;
}
.result, .saveResult {
font: normal 14px/20px "微软雅黑";
background: #FFFFFF;
}
label {
width: 100px;
height: 30px;
color: red;
font: normal 20px/30px "宋体";
text-align: center;
display: block;
margin: 0 auto;
}
.subSearch, .subCreate {
width: 200px;
height: 20px;
}
input[type=button] {
width: 50px;
height: 25px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="mian">
<!--员工查询-->
<div class="search">
<label>员工查询</label> 请输入查询员工编号:
<input type="text" class="subSearch" id="keyword" placeholder="请输入员工编号" />
<input type="button" name="" id="search" value="Search" />
<div class="result" id="result"></div>
</div>
<!--员工创建-->
<div class="create">
<label>员工创建</label> 请输入员工编号:
<input type="text" class="subCreate" id="cNum" placeholder="请输入员工编号" />
<br /> 请输入员工姓名:
<input type="text" class="subCreate" id="cName" placeholder="请输入员工姓名" />
<br /> 请选择员工性别:男
<input type="radio" name="sex" id="cSex" value="男" /> 女<input type="radio" name="sex" value="女" />
<br /> 请输入员工职称:
<input type="text" class="subCreate" id="cJob" placeholder="请输入员工职称" />
<input type="button" value="Save" id="save" />
<div class="saveResult" id="saveResult"></div>
</div>
</div>
<script src="js/jquery-3.2.0.js"></script>
<script type="text/javascript">
$(function() {
//search
$('#search').click(function() {
$.ajax({
type: "get",
url: "http://192.168.2.133:81/serverjson.php?number=" + $('#keyword').val(),
datatype: "json",
success: function(data) {
if(data.success) {
$('#result').html(data.msg);
} else {
$('#result').html("出现错误:" + data.msg);
}
},
error: function(jqXHR) {
alert("发生错误" + jqXHR.status);
}
});
})
//save
$('#save').click(function(){
$.ajax({
type:"post",
url:"http://192.168.2.133:81/serverjson.php",
datatype:"json",
data:{
name:$('#cName').val(),
number:$('#cNum').val(),
sex:$('#cSex').val(),
job:$('#cJob').val()
},
success:function(data){
if(data.success){
$('#saveResult').html(data.msg);
}else{
$('#saveResult').html(data.msg);
}
},
error:function(jqXHR){
alert("发生错误:"+jqXHR.status);
}
});
})
})
</script>
</body>
</html>