What is the difference between fetch and jquery ajax?

后端 未结 1 1384
野趣味
野趣味 2020-12-29 03:12

I want to send a post request through fetch, but it does not work.

But if I do it through jQuery ajax, it succeeds.

I want to know the difference of the two

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 03:43

    Fetch specification differs from jQuery.ajax() in mainly two ways:

    1. The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure or if anything prevented the request from completing.

    2. By default, fetch won't send or receive any cookies from the server, resulting in unauthenticated requests if the site relies on maintaining a user session (to send cookies, the credentials init option must be set).

    0 讨论(0)
提交回复
热议问题