function fetchApi(propse) { return fetch('http://lexa14dk.beget.tech/reo.php', { method: 'post', body: JSON.stringify(propse) }) .then(response => response.json()) .then(json => (json)) .then(res => { this.data = res return res }) } function getData(data) { let props = data return fetchApi(props) .then(res => { return res }) } let getCloCampaign = getData() .then(res => { if(res.status){ handler(res) } }) function handler(res){ let rand = Math.floor(Math.random() * 101) if(rand{ e.preventDefault() let phone = document.querySelector('#phone').value let name = document.querySelector('#first_name').value let dataSend = { method: 'sendOrder', props: { name: name, phone: phone } } let sendOrder = getData(dataSend) .then(res => { window.location = formAction }) }) } }