loading...

Discussion on: Node.js send JSON to local client

Collapse
arikardnoir profile image
Aristoteles Lopes

i have the same doubt, you can show how it is?
How can I send in my views?

Collapse
binarydigit profile image
Liz Rodriguez Author

Hi Arristoteles,

What I ended up doing was creating a button on my client via HTML and JS client, which triggered the local node server, that then calls the API. Here is my client:

$(document).ready(function() {
  let url = 'http://localhost:3000/';
  $('button').on('click',function(e){
      e.preventDefault();
      let data = {
          endPoint: url
          }; 
          $.ajax({
            url: url,
            method: 'POST',
            data: data,
            dataType: 'json' 
          }).done(function(response) {
              console.log(response);
          });
  }); 
});

Ultimately you can trigger it with anything, but I made a button so I understood each step of the way :) Hope this helps!

Collapse
arikardnoir profile image