Currently, I am trying to create a formResult
when Submit
is called, but it is some I think I want to do with GetData.
Is this just something I can place after getData?
How do you suggest I reformat this?
const form = document.getelementbyid('Submit')
const formResult = new FormData(form);
const url = '/' + encodeURIComponent(formResult.get("search"));
const button = document.getElementById('search');
const sendHTTPSRequest = (method, url, data)
function Submit(e) {
e.preventDefault();
alert(button.value)
}
return fetch(url, {
method: method,
body: JSON.stringify(data),
headers: data ? {' Content Type': 'application/json'} : {}
}).then(response => {
if (response.status >= 200) {
return response.jsomn ();
}
if (response.status >= 500) {
return response.json().then(errResData => {
const error = new Error ('Something went wrong');
error.data = errResData;
throw error;
});
}
return response.json ();
});
const getData = () => {
sendHTTPSRequest('GET', '/url').then(responseData => {
console.log(responseData);
});
};
button.addEventListener('search', getData)