(/en-US/docs/Web/API/Request/formData) / [ ` Response.formData() ` ](/en-US/docs/Web/API/Response/formData)
  * [ ` Request.json() ` ](/en-US/docs/Web/API/Request/json) / [ ` Response.json() ` ](/en-US/docs/Web/API/Response/json)
  * [ ` Request.text() ` ](/en-US/docs/Web/API/Request/text) / [ ` Response.text() ` ](/en-US/docs/Web/API/Response/text)

This makes usage of non-textual data much easier than it was with XHR.

Request bodies can be set by passing body parameters:

js

    
    
    const form = new FormData(document.getElementById("login-form"));
    fetch("/login", {
      method: "POST",
      body: form,
    });
    

Both request and response (and by extension the ` fetch() ` function), will
try to intelligently determine the content type. A request will also
automatically set a ` Content-Type ` header if none is set in the [ ` options
` ](/en-US/docs/Web/API/fetch#options) parameter.

##  Feature detection

Fetch API support can be detected by checking for the existence of [ ` Headers
` ](/en-US/docs/Web/API/Headers) , [ ` Request ` ](/en-
US/docs/Web/API/Request) , [ ` Response ` ](/en-US/docs/Web/API/Response) or [
` fetch() ` ](/en-US/docs/Web/API/fetch) on the [ ` Window ` ](/en-
US/docs/Web/API/Window) or [ ` Worker ` ](/en-US/docs/Web/API/Worker) scope.
For example:

js

    
    
    if (window.fetch) {
      // run my fetch request here
    } else {
      // do something with XMLHttpRequest?
    }
    

##  Differences from ` jQuery.ajax() `

The ` fetch ` specification differs from ` jQuery.ajax() ` in the following
significant ways:

  * The promise returned from ` fetch() ` won't reject on HTTP errors even if the response is an HTTP 404 or 500. Instead, as soon as the server responds with headers, the promise will resolve (with the [ ` ok ` ](/en-US/docs/Web/API/Response/ok "ok") property of the response set to ` false ` if the response isn't in the range 200â299). The promise will only reject on network failure or if anything prevented the request from completing. 
  * Unless ` fetch() ` is called with the [ ` credentials ` ](/en-US/docs/Web/API/fetch#credentials) option set to ` include ` , ` fetch() ` : 
    * won't send cookies in cross-origin requests 
    * won't set any cookies sent back in cross-origin responses 
    * As of August 2018, the default credentials policy changed to same-origin. 

##  See also

  * [ ServiceWorker API ](/en-US/docs/Web/API/Service_Worker_API)
  * [ HTTP access control (CORS) ](/en-US/docs/Web/HTTP/CORS)
  * [ HTTP ](/en-US/docs/Web/HTTP)
  * [ Fetch polyfill ](https://github.com/github/fetch)
  * [ Fetch examples on GitHub ](https://github.com/mdn/dom-examples/tree/main/fetch)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Aug 18, 2023  by  [ MDN contributors ](/en-
US/docs/Web/API/Fetch_API/Using_Fetch/contributors.txt) .

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/api/fetch_api/using_fetch/index.md?plain=1 "Folder: en-
us/web/api/fetch_api/using_fetch \(Opens in a new tab\)") â¢  [ Report a
problem with this content
](https://github.com/mdn/content/issues/new?template=page-report.yml&mdn-
url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FFetch_API%2FUsing_Fetch&metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-
us%2Fweb%2Fapi%2Ffetch_api%2Fusing_fetch%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FFetch_API%2FUsing_Fetch%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-
us%2Fweb%2Fapi%2Ffetch_api%2Fusing_fetch%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2Faae16b81e18d13dd006d418983558578563e97