fork download
  1. const GETdata = new Array()
  2. const requestURL = 'http://localhost:3000/data'
  3.  
  4. function sendRequest(method, url) {
  5. const headers = {
  6. 'Content-Type': 'application/json',
  7. }
  8.  
  9. return fetch(url, {
  10. method: method,
  11. headers: headers
  12. }).then(response => {
  13. if (response.ok) {
  14. return response.json()
  15. }
  16.  
  17. return response.json().then(error => {
  18. const e = new Error('Что-то пошло не так')
  19. e.data = error
  20. throw e
  21. })
  22. })
  23. }
  24.  
  25. sendRequest('GET', requestURL)
  26. .then(data => {
  27. data.forEach(element => {
  28. GETdata.push(element)
  29. });
  30. })
Runtime error #stdin #stdout #stderr 0.35s 42832KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "fetch" is not defined.