-4

Here is the server-side code snipped that handles GET request:

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");
})

And this is the code in the client-side that triggers the request:

    $("#load-html").click(function() {
        $.get("/new-html")
    })

The index.hml itself is rendered when the page is loaded and request with root url is made.

What I want is when I hit button with id=load-html to receive and render completely new html file returned by the server.

Hairi
  • 3,318
  • 2
  • 29
  • 68
  • 3
    Read the docs: http://api.jquery.com/jQuery.get/ You are requesting the file, but discarding it. –  Dec 20 '17 at 14:52
  • I have read thi. It doesn't tell me how to render a valid html file. I dont want to nest html elements. Instead I want to load a complete html with the DOCTYPE body head and all that sh*t – Hairi Dec 20 '17 at 14:55
  • What exactly do you mean? Put the received document inside an ` –  Dec 20 '17 at 14:56
  • I am afraid you dont understand my questiion – Hairi Dec 20 '17 at 14:57
  • I'm trying my best, and I'm not slow or anything. You are explaining it badly. WHERE do you want the browser to render the file...? –  Dec 20 '17 at 14:57
  • @Chris G Never mind Radar155 got the idea. – Hairi Dec 20 '17 at 15:00
  • Duplicate of https://stackoverflow.com/questions/503093/how-to-redirect-to-another-webpage –  Dec 20 '17 at 15:11

1 Answers1

0

You should use a link tag in your index.html page

<a href="/new-html">some text</a>

If you want to use javascript:

$("#load-html").click(function() {
    window.location.href = 'http://yourdomain.com/new-html'
})
radar155
  • 1,796
  • 2
  • 11
  • 28