Setting xmlhttpRequest.setRequestHeader to call ajax?

When I have ajax call, why should I set xmlhttpRequest.setRequestHeader? is it obvious from the ajax object that we are sending an ajax request.

+3
source share
1 answer

You must first understand that an AJAX request is an HTTP request. When you add

xmlhttp.setRequestHeader('Content-Type','XXXXXXXXX');

he adds a header that determines what data will be contained in the request body. application/x-www-form-urlencodedmeans that the data will be form data. The data format may be something else. This is precisely the fact that these forms are the most common that you will send to the server.

+3
source

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


All Articles