Why do we pass null to XMLHttpRequest.send?

前端 未结 4 1537
温柔的废话
温柔的废话 2020-12-15 03:41

Why is send so often called as

xhr.send(null)

instead of

xhr.send()

?

W3, MDN, and M

4条回答
  •  醉梦人生
    2020-12-15 04:30

    The XMLHttpRequest.send() method sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent. If the request is synchronous, this method doesn't return until the response has arrived. send() accepts an optional argument for the request body. If the request method is GET or HEAD, the argument is ignored and request body is set to null.

提交回复
热议问题