本次介绍Express模块主要以一个小栗子来实现,涉及到前台的Ajax(post,get,jsonp)请求,静态文件的请求,后台涉及到路由相关概念
前台html页面(由于前台页面较少,将js代码返回的处理数据放在了一起)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>express模块</title>
<script src="./static/js/jquery.min.js"></script>
</head>
<body>
<input type="text" placeholder="value" id="v1">
<input type="password" placeholder="value" id="v2"><br>
<button>ajax_get请求</button>
<button>ajax_post请求传递键值对</button>
<button>ajax_jsonp请求</button>
<button>ajax_post请求传递json数据</button>
<script>
$(()=>{
$('button:eq(0)').click(()=>{
//ajax_get请求
$.ajax({
url:'http://127.0.0.1:8080/ajax_get',
type:'get',
async:true,
dataType:'json',
data:{username:$('#v1').val(),password:$('#v2').val()},
success:(data)=>{
console.log(data);
}
})
});
$('button:eq(1)').click(()=>{
//ajax_post请求传递键值对
$.ajax({
url:'http://127.0.0.1:8080/ajax_postKeyValue',
type:'post',
as