How to send or receive HTTP headers in JavaScript
Typically a server-side language is used to work with headers, but you can also try JavaScript (JS).
How to send HTTP request headers
You can send JavaScript headers using Ajax requests. In a pure language, without using libraries, it might look like this:
var request = new XMLHttpRequest ();
request.open ('GET', document.location, false);
request.setRequestHeader ('Accept', 'text / plain');
request.setRequestHeader ('Content-Type', 'text / plain');
request.setRequestHeader ('Content-Language', 'en-US');
request.send (null);
request.getAllResponseHeaders (). toLowerCase ();
How to get HTTP response headers
Getting headers in JavaScript is more difficult, since this language works on the client side. But you can send a request to the server using Ajax and get roughly similar headers using the getAllResponseHeaders function. Sample code:
var request = new XMLHttpRequest ();
request.open ('GET', document.location, false);
request.send (null);
request.getAllResponseHeaders (). toLowerCase ();
Thus, you can send or receive headers using JavaScript, and not only using server-side languages, like PHP .
Comments (0)
For commenting sign in or register.
Оставить заявку
Latest articles
- 01.03.26IT / Уроки PHP Уроки простыми словами. Урок 3. Все операторы PHP с примерами, с выводом работы кода на экран.
- 28.02.26IT / Уроки PHP Уроки простыми словами. Урок 2. Типы данных в PHP с примерами.
- 27.02.26IT / Уроки PHP Уроки простыми словами. Урок 1. Коротко о языке веб-программирования PHP. Основы синтаксиса.
- 26.02.26IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 31.01.26IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes
Popular sections
Eqsash (Tools)
Share this
Subscribe to
YouTube
Books
Am (Мессенджер)
Общение смайликами со звуком.
Не работает видео? Смотреть в VK- Download APK-файл (Android);
- Веб-версия (и PWA);
- Page проекта.
21003