Skip to content

Commit 43b7c9a

Browse files
committed
Added reference links to the 'AJAX Request' page explaining the possible inconsistency of isAJAX() [ci skip]
1 parent 77d69b3 commit 43b7c9a

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

user_guide_src/source/concepts/http.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ is an object-oriented representation of the HTTP request. It provides everything
9797
The request class does a lot of work in the background for you, that you never need to worry about.
9898
The ``isAJAX()`` and ``isSecure()`` methods check several different methods to determine the correct answer.
9999

100+
.. note:: The ``isAJAX()`` method depends on the ``X-Requested-With`` header, which in some cases is not sent by default in XHR requests via JavaScript (i.e. fetch). See the AJAX Requests </general/ajax> section on how to avoid this problem.
101+
102+
::
103+
100104
CodeIgniter also provides a :doc:`Response class </outgoing/response>` that is an object-oriented representation
101105
of the HTTP response. This gives you an easy and powerful way to construct your response to the client::
102106

user_guide_src/source/general/ajax.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
AJAX Requests
33
##############
44

5-
The ``IncomingRequest::isAJAX()`` method uses the ``X-Requested-With`` header to define whether the request is XHR or normal. However, the most recent JavaScript implementations (ie fetch) no longer send this header along with the request, thus the use of ``IncomingRequest::isAJAX()`` becomes less reliable, because without this header it is not possible to define whether the request is or not XHR.
5+
The ``IncomingRequest::isAJAX()`` method uses the ``X-Requested-With`` header to define whether the request is XHR or normal. However, the most recent JavaScript implementations (i.e. fetch) no longer send this header along with the request, thus the use of ``IncomingRequest::isAJAX()`` becomes less reliable, because without this header it is not possible to define whether the request is or not XHR.
66

77
To get around this problem, the most efficient solution (so far) is to manually define the request header, forcing the information to be sent to the server, which will then be able to identify that the request is XHR.
88

user_guide_src/source/incoming/incomingrequest.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ be checked with the ``isAJAX()`` and ``isCLI()`` methods::
7171
. . .
7272
}
7373

74+
.. note:: The ``isAJAX()`` method depends on the ``X-Requested-With`` header, which in some cases is not sent by default in XHR requests via JavaScript (i.e. fetch). See the AJAX Requests </general/ajax> section on how to avoid this problem.
75+
76+
::
77+
7478
You can check the HTTP method that this request represents with the ``method()`` method::
7579

7680
// Returns 'post'

0 commit comments

Comments
 (0)