Node JS Server Requests using buttons

TheLovelySausage

I'm currently working on creating a menu for my Node JS application and I haven't figured out how to make server requests without using the browsers navigation bar.

My directory structure is as follows.

/application/nodeserver.js

            /screens/index.js
            /screens/other.js
            /screens/notfound.js

My nodeserver.js is as follows

// main

var gv_http = null;
var gv_filestream = null;
var gv_server = null;

// screens

var gv_index = null;
var gv_other = null;
var gv_notfound = null;

// set variables

gv_http = require('http');
gv_filestream = require('fs');
gv_server = gv_http.createServer();

gv_index = require('./screens/index');
gv_other = require('./screens/other');
gv_notfound = require('./screens/notfound');

// server

gv_server.on('request', function(request, response) {

   switch(request.url) {

      case '/':
      case '/index':
         gv_index.gui(response);
         break;

      case '/other':
         gv_other.gui(response);
         break;

      default:
         gv_notfound.gui(response);
         break;

   }

});

gv_server.listen(90);

This bit all works fine but the only way I can trigger my case statement is by typing into the browser which brings up my javascript screens.

One of the screens index.js

var gv_mainmenu = null;

gv_mainmenu = require('./elements/mainmenu');

var gui = function(response) {

   response.writeHead(200, {'Content-Type':'text/html'});

   response.write(
      '<html>' +
      '<body>'
   );

   response.write(
      '<button id="butt_index">' +
      '   index' +
      '</button>' +
      '<button id="butt_other">' +
      '   other' +
      '</button>'
   );

   response.write(
      '<h4>index</h4>'
   );

   response.write(
      '</body>' +
      '</html>'
   );

   response.end();

}

function sendrequest() {

   console.log("request sent");

}

module.exports.gui = gui;

Is it possible to simulate this using one of the html buttons? I've only seen this happen with frameworks like Express but I don't want to use one of these while still learning.

PS

I know my code may look weird to JavaScript experts but I follow the coding standards of the people I work with and we code primarily with Genero so I try to keep it familiar to them and myself.

Kevin Doveton

Easiest solution is to add an anchor tab to your buttons so they link to your new page.

'<a href="/index"><button id="butt_index">' +
  '   index' +
  '</button></a>'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Node JS - Server doesn't react to requests

From Dev

Requests to Node.js server timing out due to multiple requests

From Dev

Update and delete buttons using node.js

From Dev

Cannot connect to Node.js server using socket.io + express + webpack, requests return 404 errors

From Dev

Node.js server gets stuck after few requests when using passport

From Dev

Making requests to API using node.js

From Dev

Node.js server with multiple concurrent requests, how does it work?

From Dev

How to make node js express server handle requests in parallel

From Dev

How does a Node.js server process requests?

From Dev

Forcing HTTPS requests in node.js server on azurewebsites

From Dev

Only allow requests from mobile applications to Node.js server?

From Dev

Node.js server not returning response after certain requests

From Java

Is Kestrel using a single thread for processing requests like Node.js?

From Dev

using async Node.JS to serve HTTP requests

From Dev

How to send multiple requests(?) objects to browser using node js

From Dev

Using Q Promises to chain GET requests in node.js

From Dev

Node JS https server using only PFX

From Dev

Call to node js server using jquery ajax

From Dev

Does Node.js or another JS server tech support native shared memory between requests without serialization?

From Java

Delete Requests not persisting in node js

From Dev

Making multiple requests in node js

From Dev

how to redirect to react js application using node js, in same server?

From Dev

Node.js process.nextTick still blocking server from getting requests

From Dev

Using Q to chain Database queries using Node.js server

From Dev

How to create Node server only for POST requests

From Dev

Cannot delete buttons using js

From Dev

Change a buttons css using JS

From Dev

Node.js Can not push to global array using promises, Mongoose, and GET requests

From Dev

Youtube API using async in node.js Express for multiple dependant requests

Related Related

  1. 1

    Node JS - Server doesn't react to requests

  2. 2

    Requests to Node.js server timing out due to multiple requests

  3. 3

    Update and delete buttons using node.js

  4. 4

    Cannot connect to Node.js server using socket.io + express + webpack, requests return 404 errors

  5. 5

    Node.js server gets stuck after few requests when using passport

  6. 6

    Making requests to API using node.js

  7. 7

    Node.js server with multiple concurrent requests, how does it work?

  8. 8

    How to make node js express server handle requests in parallel

  9. 9

    How does a Node.js server process requests?

  10. 10

    Forcing HTTPS requests in node.js server on azurewebsites

  11. 11

    Only allow requests from mobile applications to Node.js server?

  12. 12

    Node.js server not returning response after certain requests

  13. 13

    Is Kestrel using a single thread for processing requests like Node.js?

  14. 14

    using async Node.JS to serve HTTP requests

  15. 15

    How to send multiple requests(?) objects to browser using node js

  16. 16

    Using Q Promises to chain GET requests in node.js

  17. 17

    Node JS https server using only PFX

  18. 18

    Call to node js server using jquery ajax

  19. 19

    Does Node.js or another JS server tech support native shared memory between requests without serialization?

  20. 20

    Delete Requests not persisting in node js

  21. 21

    Making multiple requests in node js

  22. 22

    how to redirect to react js application using node js, in same server?

  23. 23

    Node.js process.nextTick still blocking server from getting requests

  24. 24

    Using Q to chain Database queries using Node.js server

  25. 25

    How to create Node server only for POST requests

  26. 26

    Cannot delete buttons using js

  27. 27

    Change a buttons css using JS

  28. 28

    Node.js Can not push to global array using promises, Mongoose, and GET requests

  29. 29

    Youtube API using async in node.js Express for multiple dependant requests

HotTag

Archive