使用按钮实现新页面的链接并单击处理程序
以下是处理GET请求的服务器端代码段:
app.get('/', function(req, res){
res.sendFile(__dirname + "/public/html/index.html");
});
app.get("/new-html", function(req, res){
console.log("Request /new-html");
res.sendFile(__dirname + "/public/html/new.html");
})
这是客户端中触发请求的代码:
$("#load-html").click(function() {
$.get("/new-html")
})
在加载页面时会呈现index.hml本身,并使用根URL进行请求。
我想要的是当我点击按钮与id=load-html
接收并呈现服务器返回的全新html文件。
您应该在index.html页面中使用链接标记
<a href="/new-html">some text</a>
如果你想使用javascript:
$("#load-html").click(function() {
window.location.href = 'http://yourdomain/new-html'
})
使用按钮实现新页面的链接并单击处理程序
以下是处理GET请求的服务器端代码段:
app.get('/', function(req, res){
res.sendFile(__dirname + "/public/html/index.html");
});
app.get("/new-html", function(req, res){
console.log("Request /new-html");
res.sendFile(__dirname + "/public/html/new.html");
})
这是客户端中触发请求的代码:
$("#load-html").click(function() {
$.get("/new-html")
})
在加载页面时会呈现index.hml本身,并使用根URL进行请求。
我想要的是当我点击按钮与id=load-html
接收并呈现服务器返回的全新html文件。
您应该在index.html页面中使用链接标记
<a href="/new-html">some text</a>
如果你想使用javascript:
$("#load-html").click(function() {
window.location.href = 'http://yourdomain/new-html'
})