用express框架制作网页时怎么用ajax实现局部刷新
2017-04-04 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
express框架制作网页时用ajax实现局部刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/javascripts/jquery-3.1.0.min.js"></script>
</head>
<body>
<form action="javascript:;" id="form" >
<div style="width: 400px;height: 400px;background-color: yellow"></div>
<input type="submit" id="button" onclick="tijiao()" value="提交">
</form>
<script src="/javascripts/ajax.js"></script>
</body>
</html>
==============================================================================
这是ajax.js里面的代码
function tijiao() {
var formData = new FormData($("#from")[0]);
$("#button").click(function() {
$.ajax({
type: "get",
url: "/users/shuaxin",
data: formData,
contentType: "application/json; charset=utf-8",
dataType: "ejs",
success: function(data) {
alert(data.d);
},
error: function(err) {
alert(err);
}
});
return false;
});
};
==============================================================================
这是routes文件夹里users的代码
router.get('/shuaxin', function(req,res,next){
res.render("tp.ejs");
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/javascripts/jquery-3.1.0.min.js"></script>
</head>
<body>
<form action="javascript:;" id="form" >
<div style="width: 400px;height: 400px;background-color: yellow"></div>
<input type="submit" id="button" onclick="tijiao()" value="提交">
</form>
<script src="/javascripts/ajax.js"></script>
</body>
</html>
==============================================================================
这是ajax.js里面的代码
function tijiao() {
var formData = new FormData($("#from")[0]);
$("#button").click(function() {
$.ajax({
type: "get",
url: "/users/shuaxin",
data: formData,
contentType: "application/json; charset=utf-8",
dataType: "ejs",
success: function(data) {
alert(data.d);
},
error: function(err) {
alert(err);
}
});
return false;
});
};
==============================================================================
这是routes文件夹里users的代码
router.get('/shuaxin', function(req,res,next){
res.render("tp.ejs");
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询