Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BrowserKit] Documented the new xmlHttpRequest() method #9518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions components/browser_kit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ The value returned by the ``request()`` method is an instance of the
:doc:`DomCrawler component </components/dom_crawler>`, which allows accessing
and traversing HTML elements programmatically.

The :method:`Symfony\\Component\\BrowserKit\\Client::xmlHttpRequest` method,
which defines the same arguments as the ``request()`` method, is a shortcut to
make AJAX requests::

use Acme\Client;

$client = new Client();
// the required HTTP_X_REQUESTED_WITH header is added automatically
$crawler = $client->xmlHttpRequest('GET', '/');

.. versionadded:: 4.1
The ``xmlHttpRequest()`` method was introduced in Symfony 4.1.

Clicking Links
~~~~~~~~~~~~~~

Expand Down
22 changes: 17 additions & 5 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ returns a ``Crawler`` instance.
)

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

$client->request(
Expand All @@ -369,9 +369,8 @@ returns a ``Crawler`` instance.
array(),
array(),
array(
'CONTENT_TYPE' => 'application/json',
'HTTP_REFERER' => '/foo/bar',
'HTTP_X-Requested-With' => 'XMLHttpRequest',
'CONTENT_TYPE' => 'application/json',
'HTTP_REFERER' => '/foo/bar',
)
);

Expand Down Expand Up @@ -441,6 +440,19 @@ script::

$client->insulate();

AJAX Requests
~~~~~~~~~~~~~

The Client provides a :method:`Symfony\\Component\\BrowserKit\\Client::xmlHttpRequest`
method, which has the same arguments as the ``request()`` method, and it's a
shortcut to make AJAX requests::

// the required HTTP_X_REQUESTED_WITH header is added automatically
$client->xmlHttpRequest('POST', '/submit', array('name' => 'Fabien'));

.. versionadded:: 4.1
The ``xmlHttpRequest()`` method was introduced in Symfony 4.1.

Browsing
~~~~~~~~

Expand Down