-1

I have a local server running using Node.js at localhost:3000 and it runs a static html page which has a button.

When I click the button I want it to 'go' to 'localhost:3000/buttonClicked' but I don't actually want the html page to change at all. I have the server handling the GET request so the only problem is I don't want to move away from my localhost:3000 page.

So I want to go to localhost:3000/buttonClicked, have the server do what it does when user goes to that page(this part I've completed already), but I don't actually want the user to move away from localhost:3000

I think I can use AJAX to do this but I have no idea if it's difficult or how I would do it.

Any help is appreciated.

joey
  • 3
  • 1

1 Answers1

-1

If you use jQuery, there is a function called load that'll do this for ya.

You can do $('body').load( './buttonClicked' );

taveras
  • 485
  • 3
  • 12
  • i think he just wants the server action to run without updating the page. – Segfault Oct 16 '14 at 20:09
  • 1
    Make ajax request on button click. If input type is submit "return false" in js on click. – ranjeet Oct 16 '14 at 20:15
  • Ah sorry, misunderstood! You can easily do this `$.get('/buttonClicked');` If you actually need to do something with whatever HTML is outputted inside the localhost:3000/buttonClick page, then you can add a callback like so: `$.get('/buttonClicked', function(response) { console.log(response); });` – taveras Oct 16 '14 at 21:18