Note: after I wrote this up I understood better that you want to post data to an endpoint. You can use fetch() to do that too. You'll just use these instructions
] to do that.
1. make sure your button is _not_ wrapped inside a <form> element.
<button onclick="getNameValue()">Get Name</button>
Now we need t use the fetch API
] to get the data you want.
This will occur asynchronously so the page isn't refreshed but instead the data is just retrieved.
Now, I don't know what domain you are retrieveing data from but you have to retrieve data from the same URL where your page is running or you get a CORS (cross-origin request) error.
.then(response => response.text())
.then(data => console.log(data));
the sample can be run by opening your Browser console (F12 in most browsers) while you are reading this page -- then copy just the 3 fetch lines and paste them on the console and hit <ENTER>.
When you do that you'll see that it fetches the main codeproject page as text()
and then uses that as the data input to a console.log(data) call which will display all the data in the console for you.
Obviously, this fetch call would contain a URL to the domain and specific URL which will return your data.