get data from api in javascript
const GetData = []; useEffect(() => { fetch(API_URL) .then((res) => res.json()) .then((data) => { GetModesData.push(...data); setDataState(GetData.map((d) => d.modeName)); }); }, []);
get data from api in javascript
const GetData = []; useEffect(() => { fetch(API_URL) .then((res) => res.json()) .then((data) => { GetModesData.push(...data); setDataState(GetData.map((d) => d.modeName)); }); }, []);
using apis in javascript
// Create a request variable and assign a new XMLHttpRequest object to it. var request = new XMLHttpRequest() // Open a new connection, using the GET request on the URL endpoint request.open('GET', url, true) request.onload = function () { // Begin accessing JSON data here } // Send request request.send()
fetch
var formData = new FormData(); var fileField = document.querySelector("input[type='file']"); formData.append('username', 'abc123'); formData.append('avatar', fileField.files[0]); fetch('https://example.com/profile/avatar', { method: 'PUT', body: formData }) .then(response => response.json()) .catch(error => console.error('Error:', error)) .then(response => console.log('Success:', response));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us