Professional Documents
Culture Documents
object or the newer fetch() function. Here is an example of how to use fetch():
javascriptCopy code
fetch ( 'https://example.com/data.json' ) . then ( response => response. json ()) . then ( data => console . log (data))
. catch ( error => console . error (error));
You can also specify additional options when making the request, such as HTTP
headers or request body data. Here is an example:
javascriptCopy code
fetch ( 'https://example.com/api/data' , { method : 'POST' , headers : { 'Content-Type' : 'application/json' },
body : JSON . stringify ({ key : 'value' }) }) . then ( response => response. json ()) . then ( data =>
console . log (data)) . catch ( error => console . error (error));