If you're planning on making an API call using
fetch()
then you probably intend on sending the value across to the API. At the moment you're performing a simple GET request with no additional input, so that's probably not going to work.
You can use
the fetch() document[
^] as a starting point for what you're trying to accomplish. We're not going to build the code for you, but you have a good starting point with what you've already tried. You need to work out whether the API is expecting a JSON (application/json) request or a form (application/x-www-form-urlencoded).
fetch('https://api.domain/path', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
phoneNumber: document.getElementById('..').value
})
})
.then(..)
.catch(..)
const form = new FormData();
form.append('phoneNumber', document.getElementById('..').value);
fetch('https://api.domain/path', {
method: 'POST',
body: form
})
.then(..)
.catch(..)