Retrieves the specified resource from the network using HTTPS.
The fetch()
function fetches an HTTPS resource from the network. It returns
a Promise that resolves to a WixFetchResponse
object representing the HTTP response to the request.
Responses with an HTTP status code in the ranges 2xx, 4xx, and 5xx are
considered fulfilled. Use the httpResponse.ok
property to confirm that the HTTP request was successful with a response
code in the 2xx range.
The optional WixFetchRequest
object contains information about an HTTPS request.
Additional functionality is available in each of the respective Fetch API implementations.
Notes:
Some common errors when using the fetch()
function are described here along with possible solutions.
fetch()
call due to a CORS restriction, move the fetch()
call to the backend as described in Accessing 3rd-Party Services.
The url of the resource to fetch.
Options for the fetch operation.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Retrieves the specified JSON resource from the network using HTTPS.
The getJSON()
function retrieves a JSON resource from the network. It returns
a Promise that resolves to a JSON object representing the response to the request.
To use getJSON
, import it from wix-fetch
:
Retrieving the JSON object is performed using the GET method, regardless of
what is specified in the options
parameter.
The Accept
header is assumed to be application/json
by default, but you
can override it by explicitly setting a different value for Accept
.
The optional WixFetchRequest
object contains information about an HTTPS request.
Additional functionality is available in each of the respective Fetch API implementations.
Notes:
Some common errors when using the getJSON()
function are described here along with possible solutions.
getJSON()
call due to a CORS restriction, move the getJSON()
call to the backend as described in Accessing 3rd-Party Services.
The url of the JSON resource to retrieve.
Options for the retrieval operation.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.