L
L
Leonid2016-09-27 12:46:38
PHP
Leonid, 2016-09-27 12:46:38

Passing your data in HTTP headers in response to an Ajax request - how?

From the server, in addition to the main content in the response to the Ajax request, can I also send my additional HTTP headers for their further use in JavaScript?

For example: I have an HTML page, an Ajax request to a PHP script is made in the JavaScript code. The PHP script issues some additional HTTP header through the header() function, and I use it in JavaScript.

Is there an example of such an interaction?

What HTTP headers can I use for my purposes - ie. to pass from PHP the data I need to JavaScript in addition to the main response to the request?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivanq, 2016-09-27
@Ivanq

The meaning is a bit incomprehensible, but you can take something like X-Data-blablabla.
Headers can be retrieved via getAllResponseHeaders()

T
theg4sh, 2016-09-27
@theg4sh

You can use all the headers that are described in the RFC HTTP
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Also for a request with a custom HTTP request name, take a look here:
https://developer. mozilla.org/en-US/docs/Web/HTTP/...
Yes, and in general, get acquainted with
https://developer.mozilla.org/en/docs/Web/HTTP/%D0...
There are plenty of examples when googling "ajax custom request".

S
SharuPoNemnogu, 2016-09-27
@SharuPoNemnogu

you can. For example, header('Content-type: application/json');

L
Leonid, 2016-09-27
@easycode

those. if I understand correctly, I can send my own HTTP header from PHP and read it safely through getResponseHeader. What is the best name for your title? Are there any restrictions? Rules?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question