Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e192330

Browse filesBrowse files
committed
minor #9518 [BrowserKit] Documented the new xmlHttpRequest() method (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [BrowserKit] Documented the new xmlHttpRequest() method This fixes #9381. Commits ------- 5f57f40 Documented the new xmlHttpRequest() method
2 parents b2463ce + 5f57f40 commit e192330
Copy full SHA for e192330

File tree

2 files changed

+30
-5
lines changed
Filter options

2 files changed

+30
-5
lines changed

‎components/browser_kit.rst

Copy file name to clipboardExpand all lines: components/browser_kit.rst
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ The value returned by the ``request()`` method is an instance of the
7575
:doc:`DomCrawler component </components/dom_crawler>`, which allows accessing
7676
and traversing HTML elements programmatically.
7777

78+
The :method:`Symfony\\Component\\BrowserKit\\Client::xmlHttpRequest` method,
79+
which defines the same arguments as the ``request()`` method, is a shortcut to
80+
make AJAX requests::
81+
82+
use Acme\Client;
83+
84+
$client = new Client();
85+
// the required HTTP_X_REQUESTED_WITH header is added automatically
86+
$crawler = $client->xmlHttpRequest('GET', '/');
87+
88+
.. versionadded:: 4.1
89+
The ``xmlHttpRequest()`` method was introduced in Symfony 4.1.
90+
7891
Clicking Links
7992
~~~~~~~~~~~~~~
8093

‎testing.rst

Copy file name to clipboardExpand all lines: testing.rst
+17-5Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ returns a ``Crawler`` instance.
359359
)
360360

361361
The ``server`` array is the raw values that you'd expect to normally
362-
find in the PHP `$_SERVER`_ superglobal. For example, to set the ``Content-Type``,
363-
``Referer`` and ``X-Requested-With`` HTTP headers, you'd pass the following (mind
362+
find in the PHP `$_SERVER`_ superglobal. For example, to set the
363+
``Content-Type`` and ``Referer`` HTTP headers, you'd pass the following (mind
364364
the ``HTTP_`` prefix for non standard headers)::
365365

366366
$client->request(
@@ -369,9 +369,8 @@ returns a ``Crawler`` instance.
369369
array(),
370370
array(),
371371
array(
372-
'CONTENT_TYPE' => 'application/json',
373-
'HTTP_REFERER' => '/foo/bar',
374-
'HTTP_X-Requested-With' => 'XMLHttpRequest',
372+
'CONTENT_TYPE' => 'application/json',
373+
'HTTP_REFERER' => '/foo/bar',
375374
)
376375
);
377376

@@ -441,6 +440,19 @@ script::
441440

442441
$client->insulate();
443442

443+
AJAX Requests
444+
~~~~~~~~~~~~~
445+
446+
The Client provides a :method:`Symfony\\Component\\BrowserKit\\Client::xmlHttpRequest`
447+
method, which has the same arguments as the ``request()`` method, and it's a
448+
shortcut to make AJAX requests::
449+
450+
// the required HTTP_X_REQUESTED_WITH header is added automatically
451+
$client->xmlHttpRequest('POST', '/submit', array('name' => 'Fabien'));
452+
453+
.. versionadded:: 4.1
454+
The ``xmlHttpRequest()`` method was introduced in Symfony 4.1.
455+
444456
Browsing
445457
~~~~~~~~
446458

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.