Answer the question
In order to leave comments, you need to log in
How to know that a JSON request has been received in PHP?
Is it possible to find out that an Ajax request has been received to receive JSON.
I probably didn't express myself correctly.
The point is this.
There is a certain catalog, when you enter, you need to make sure that the page opens and the goods are loaded. Here I think is it possible to find out that the server received an ajax request to receive JSON
Answer the question
In order to leave comments, you need to log in
<?php
if (! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
print "Поступил Ajax-запрос";
}
@dpr gave good advice, but if you really want to hide the kitchen from the user, then why not use the features built into the HTTP protocol?
On the client side
Server side
if ($_SERVER['HTTP_ACCEPT'] == 'application/json') {
// тут генерируем JSON
} else {
// тут генерируем HTML
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question