How to identify queries initiated by the new sampling standard? How to define an AJAX request in general?

It may be useful on the server to know that the incoming request is AJAX.

Most js libraries use XMLHttpRequestand therefore provide HTTP_X_REQUESTED_WITH: XMLHttpRequest, but neither the Chrome implementation nor the new Github polyfillfetch uses a similar header. So how can you find that AJAX request?

Why is the request identifying its initiator not applied through standards for fetchand XMLHttpRequest? Should something else be used to make decisions (for example, clients providing the type of content they expect in response)?

+4
source share
2 answers

Mark this issue on Github polyfill , especially this comment.

Since the header is X-Requested-Withnot standard, it uses a wrapper that provides some of the missing actions.

If you need more recommendations, check out these lines of shell code:

function headers(options) {
  options = options || {}
  options.headers = options.headers || {}
  options.headers['X-Requested-With'] = 'XMLHttpRequest'
  return options
}
+4
source

Why a request indicating that its initiator is not applied through standards

Because it does not matter.

HTTP clients request what they want to receive. The server must provide them to them.

- , , . -.

- (, , , )?

.

Accept , , , HTTP- .

+2

Source: https://habr.com/ru/post/1615501/


All Articles